FactChecker
Science Advisor
Homework Helper
- 9,343
- 4,623
It is notoriously difficult to design an algorithm for a random number generator. Anything that one thinks will be random is very likely to display patterns that are clear to see when looked at the right way. Your program looks like an example of that. A classic book which contains a lot on the subject is Knuth, "Art of Computer Programming, Volume 2: Seminumerical Algorithms" .fbs7 said:Another example of a generator that will (eventually, and very very very slowly) not repeat is this one, for say 8-bit integers (or whatever size integers we choose):
Code:initialize a[i] = 0 for i in 1..N repeat calculate randomness of a[] for i = 1..N, for j = 1 to 8: invert bit j of a[i] recalculate randomness of a[] if new sequence has lower randomness, revert the bit back until randomness of a[] > desired-target
that algorithm (a brute-force search, actually) will eventually generate a non-repeating, whatever-length sequence that will pass whatever randomness criteria we set... at a cost of taking ages to process... hmm... actually this is probably the slowest random number generator ever... I should get a prize or something for that![]()