1
\$\begingroup\$

After seeing some impossibly short solutions in this SE, I began to wonder what code someone could come up with to build a pseudo-random number generator. Now given that I am new to programming, I have absolutely no idea what such generator should look like, or what language to write them in. But that did not stop me from trying some goofy things like writing PRNG, listing primes or prime tests.

So here's the deal, the challenge is to write a pseudo-random number generator that does the following things:

1.Accept a seed in the form of string, number, bits, or whatever, and generate a pseudo-random sequence based on that string. The initial seed should default to 0 if nothing is provided.

2.Accept some input N and generate a pseudo random sequence of length N. Straight forward enough. You can choose to name this whatever you want, or not at all.

3.Be deterministic, the same seed should generate the same sequence each time.

4.I have absolutely no idea how this is tested but the results should be reasonably random. So the results from your generator should be close to uniform distribution within your arbitrary sample space.

5.You can choose any mathematical formula/operation for your pseudo random generation, but it should update its internal state in a deterministic way and use that new internal state for the generation of another number.

You may not outsource your random number generation to any source, be it built in or online. Every variable update/ operation should be explicitly ordered. (things like random.randint() is banned, sorry I only know python)

I can't come up with some inventive way of scoring, so shortest program wins.

\$\endgroup\$
  • 1
    \$\begingroup\$ define "reasonably random". 1234567890123456... looks okay to me. \$\endgroup\$ – John Dvorak Feb 7 at 9:57
  • 1
    \$\begingroup\$ That's too trivial. Just take a bad RNG algorithm, like Lehmer generator with small constants, and implement it. The only way it would be interesting, is if you clearly set up a threshold for a qualifying level of randomness or a period. \$\endgroup\$ – Andriy Makukha Feb 7 at 10:01
  • 1
    \$\begingroup\$ I don't think a uniform distribution is a good criteria for randomness.. I heard that humans are bad at random for this reason, they tend to make distribution uniform and avoid repetitions, where random should do the contrary to a statical extend \$\endgroup\$ – Kaddath Feb 7 at 10:14
  • 2
    \$\begingroup\$ For uniformness I guess f(seed) = seed++ works perfectly if seed is allowed to overflow from 2^64-1 to 0... \$\endgroup\$ – my pronoun is monicareinstate Feb 7 at 10:20
  • 1
    \$\begingroup\$ Python 3, 15 bytes lambda x,s=0: 4 it is random, I swear \$\endgroup\$ – RGS Feb 7 at 10:45