Random float number generation

后端 未结 14 1610
孤城傲影
孤城傲影 2020-11-22 05:05

How do I generate random floats in C++?

I thought I could take the integer rand and divide it by something, would that be adequate enough?

14条回答
  •  日久生厌
    2020-11-22 05:40

    drand48(3) is the POSIX standard way. GLibC also provides a reentrant version, drand48_r(3).

    The function was declared obsolete in SVID 3 but no adequate alternative was provided so IEEE Std 1003.1-2013 still includes it and has no notes that it's going anywhere anytime soon.

    In Windows, the standard way is CryptGenRandom().

提交回复
热议问题