Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
588 views
in Technique[技术] by (71.8m points)

c - How to properly seed a mersenne twister RNG?

This is actually not as simple as I first thought.

In the absence of a hardware RNG, what is the best way to seed a Mersenne Twister?

Or should I say, what is an acceptable way to seed a a Mersenne Twister RNG that is used to generate UUID's?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is a nice discussion of pseudo-random number generators here including a section on the proper seeding of PRNGs (see rule 3), which uses md5sum and /dev/random or /dev/urandom to generate seeds.

This also includes a number of PRNG alogrithms which are a lot easier to code up (< 10 lines of code) than the MT but are arguably just as good (long periods and pass all of the Dieharder tests for randomness).

Further Reading:

  1. Seed std::mt19937 from std::random_device
  2. Best way to seed mt19937_64 for Monte Carlo simulations
  3. How to obtain (almost) unique system identifier in a cross platform way?

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...