2
1
I'm not even sure if this is even possible, but I think it's worth a shot.
The Challenge
Code/conceptualize a pseudo-random number generator that has the potential to produce results evenly spaced out with similar frequencies... with a twist. The random number generator has to 'loop' back after Foo iterations to its beginning state then produce the exact same results. Foo is a variable of all positive integers.
For example, if the iterations amount is 4 and the random numbers generated after 4 iterations are {93,5,80,13}, then the next 4 iterations will produce {93,5,80,13}, as will the next 4 after that and so on.
Limitations
- Random numbers can't be pre-defined. For example, the algorithm can't simply iterate over {1,2,3,4,...int.MaxValue}, up to the iteration amount then go back to the first value.
- Similar to Limitation 1, random numbers can't be cached so a set of numbers can't be generated, saved, then repeatedly returned.
- Similar to Limitation 2, the random number generator can't be 'forced' back to a certain state. Beginning seed numbers and whatnot cannot be saved.
- The RNG can't use the number of iterations its run.
In other words, the Generator has to arrive back at its beginning state solely through consecutive calculations.
Objective
Shortest code wins!
As Sp says, most random number generators necessarily loop back on themselves because they are only pseudo random and have a finite period.
– Calvin's Hobbies – 2015-05-08T06:51:19.140Yes, but that period is a defined one in this challenge. Sorry about the confusion. Changed 'any' to 'all'. – JPtheK9 – 2015-05-08T06:52:27.540
Does "all positive integers" really mean all or just up to int.max? If the latter then could someone just take the first Foo values of their language's PRNG? (Assuming the language PRNG period is larger than int.max.) – Calvin's Hobbies – 2015-05-08T06:59:29.583
All can't be practically tested, so I'd say just up to int.max. Taking the first Foo values of a default PRNG would violate Limitation 2. The PRNG has to arrive back at its beginning state solely through consecutive calculations. – JPtheK9 – 2015-05-08T07:00:56.060
But the values wouldn't be saved per se. The prng would just be restarted. – Calvin's Hobbies – 2015-05-08T07:02:53.000
Ah, true. That would violate Limitation 3 though. – JPtheK9 – 2015-05-08T07:03:43.227
2What is the objective winning criterion? Shortest code? Fastest code (which leads to more questions)? – Kyle Kanos – 2015-05-08T11:10:10.543
If you loop an integer N with steps of 3 to infinity and then use seed(n%3)/seed(n%2)+seed(n%1) to create numbers, would this break limitation 3? – dwana – 2015-05-08T13:10:33.943
I added a new limitation to clear things up, and the winning objective. @dwana That kind of violates limitation 3 but I clarified it with a new limitation. – JPtheK9 – 2015-05-08T19:57:39.687
1I think you might want give a specific criteria for what counts as "reasonably random". Different PRNGs pass different tests, but if you specify the exact testing method then everybody can be on the same boat. – Sp3000 – 2015-05-08T20:10:27.993
The ideal would be to provide code in the question that will validate the answers, so there is no confusion over which answers are valid. Testing randomness is not easy though... – trichoplax – 2015-05-08T20:15:38.407
Could I generate random numbers for foo iterations and then use those same numbers? – ASCIIThenANSI – 2015-05-08T20:31:18.913