Generating random numbers effectively

后端 未结 5 1380
故里飘歌
故里飘歌 2021-01-23 23:16

How do you generate random numbers effectively?
Every time a random number program boots up, it starts spitting same numbers as before. (I guess because of quasi nature of

5条回答
  •  无人及你
    2021-01-23 23:40

    "Seed" the random number generator by getting the number of seconds since midnight and then passing it in:

    Random rand = new Random(secs);
    

    This still does not generate perfectly random numbers, but should serve your purpose.

提交回复
热议问题