V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
flyaway
V2EX  ›  问与答

C 代码的求解释

  •  
  •   flyaway · Oct 20, 2018 · 2307 views
    This topic created in 2759 days ago, the information mentioned may be changed or developed.

    最近在阅读 word2vec 的源码的时候,发现作者用了如下的代码来生成随机数,有没有了解 C 语言的朋友帮忙解释一下。我自己无法理解。

    // Initalization
    unsigned long long next_random = 1;
    ....
    
    next_random = next_random * (unsigned long long)25214903917 + 11;
    random_value = (((next_random & 0xFFFF) / (real)65536) - 0.5) / layer1_size;
    

    其中最后两行代码出现在每一个需要随机数的地方,有没有大神帮忙解释一下这段代码是怎么生成随机数的?这个随机数是什么样的分布?

    2 replies    2018-10-20 00:32:34 +08:00
    dawn009
        1
    dawn009  
       Oct 20, 2018
    flyaway
        2
    flyaway  
    OP
       Oct 20, 2018
    @dawn009 多谢,知道方向后就容易理解了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2985 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 08:39 · PVG 16:39 · LAX 01:39 · JFK 04:39
    ♥ Do have faith in what you're doing.