2021年1月

Git设置多用户

之前在一台电脑上都是用的同一个Git账号,最近需要公司和个人的Git同时使用,发现Git的用户名和邮箱都是全局的,于是寻找了设置一台电脑上配置多用户的方法,网上乱七八糟的文章太多了,又是手动改配置文件又是弄SSH key的。

- 阅读剩余部分 -

java.util.Random中的181783497276652981

偶然间看到Random类的构造函数中有181783497276652981这么一个Magic Number, 没有定义为常量, 也没有对这个数做什么特别的说明, 感觉很奇怪, 于是好奇心驱使我扒一扒这个数字的由来:

// java version: 1.8.0_251
public class Random implements java.io.Serializable {
    // ...
    
    /**
     * The internal state associated with this pseudorandom number generator.
     * (The specs for the methods in this class describe the ongoing
     * computation of this value.)
     */
    private final AtomicLong seed;


    /**
     * Creates a new random number generator. This constructor sets
     * the seed of the random number generator to a value very likely
     * to be distinct from any other invocation of this constructor.
     */
    public Random() {
        this(seedUniquifier() ^ System.nanoTime());
    }

    private static long seedUniquifier() {
        // L'Ecuyer, "Tables of Linear Congruential Generators of
        // Different Sizes and Good Lattice Structure", 1999
        for (;;) {
            long current = seedUniquifier.get();
            long next = current * 181783497276652981L;
            if (seedUniquifier.compareAndSet(current, next))
                return next;
        }
    }

    private static final AtomicLong seedUniquifier
        = new AtomicLong(8682522807148012L);
    
    // ...
}

- 阅读剩余部分 -

加载中……