I m looking for way to generate unique random numbers based on current time using java. I m a c++ programmer and in c++ I usually seed the Random with time so at each specific moment I can get a unique random number and it works like this :
sRand((time)Null);
x=Rand();
在Java,我发现我可以使用同样的方法, 播种随机数 和这样的时间:
Random rand = new Random(System.currentTimeMillis());
Here is the problem I have used all the methods I found over the internet for generating a random number in java but none of them were truly random and they ranged from negative to positive numbers. For example:
Random rand = new Random(System.currentTimeMillis());
int x=rand.nextInt(); // or long or float ...
我得到的是一系列并非真正随机的数字,结果与C++中的结果完全不同。
我只是想知道 在Java里做这件事的最好方法是什么, 一些类似或非常接近TAC数字的一代。