It is possible to generate a truly random number using Java or do I need to use a third party SDK or API? I need to generate 1000's of random numbers at the same time and I'm seeing lots of duplicates using the traditional method.
There are websites that can produce truly random numbers using a Cesium (or other) source. Some may be free for small quantities of random numbers and others may charge if you'll be needing large quantities of them, but they are truly random.
what is your definition of "truly random"? Using java, you can get random-seeming numbers - i.e numbers that are equally distributed across a range and that are (almost) impossible to predict. But any pure-code implemented algorithm is pretty much guaranteed to not be completely random, since anyone who a) knows the algorithm, and b) knows the seed will be able to reproduce the sequence.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
"I'm seeing lots of duplicates": by its very definition, random numbers do not guarantee uniqueness.
A problem I had with pseudo-random numbers is that they are mostly "evenly distributed". This was readily apparent in a game I was working on 10 years ago. I was unable to come up with a trick to randomize the random numbers which is how I tripped across the website (sorry, don't remember the name or URL).
Ashley McScott wrote:I need to generate 1000's of random numbers at the same time and I'm seeing lots of duplicates using the traditional method.
As Carey pointed out, randomness and uniqueness are two different things. Random sequences do not guarantee uniqueness. If you need both randomness and uniqueness, then first generate a list of unique numbers and then shuffle them to arrange them in some random order, then iterate over the list.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck