In Java cross plateform ably, there is no time to seed the random generator

I initialize two random number generators on two threads almost at the same time. I want the behavior of the two generators to be completely different I often call random. On two generators one after the other nextInt(7). Use system Currenttimemillis () is not a good idea because it seems that my computer is so fast that the numbers obtained from the two generators are likely to be the same So is there a way to configure random, although they are called one by one, but they still behave differently? I want the solution to be cross platform compatible, so any platform specific idea (such as reading from / dev / random) is unacceptable Thank you for your help

Solution

One way: use UUID (GUID) conversion (hash? But maybe not just cast) to seed each random instance into long

> Generate UUID in Java

Other answers suggest using nanotime, which may be suitable depending on the speed of the hardware, but I prefer the UUID route

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>