I'm looking for a Pseudo-Random Number Generation algorithm capable of producing a random 128-/256-bit number. Security and cryptographic integrity are not important; simplicity and performance are valued above all else. Ideally, the algorithm will be usable on modern mobile phone platforms. Can you recommend such an algorithm? Is it feasible? Thanks in advance!
-
5Why not use something built into your language or toolkit's common library? There's no need to re-invent the wheel, especially if simplicity matters. – Cody Gray - on strike Jun 02 '11 at 15:41
-
Portability is a concern, so the language is not important; I should have clarified that. Also, many languages' random number implementations only provide up to 32-bit numbers. – Dan Jun 02 '11 at 16:36
-
1@Dan One possibility is to use the standard implementation and extend to more bits if necessary (i.e. concat four 32-bit numbers and you'll have 128 bits). – Howard Jun 02 '11 at 16:41
-
@Howard The problem with that is that there are still only 2^32 possible attainable sequences of random numbers. – Dan Jun 02 '11 at 16:52
-
@Dan that depends on your PRNG. It doesn't have to be the case that a rng with 32 bits is periodic with <= 2^32. This holds only for simple ones which do not have any internal state. – Howard Jun 02 '11 at 16:56
-
1Most heavyweight PRNGs offer only 32 bits at the API but permute the state of a register at least as large as your output size requirement. Successive calls would normally just copy out 32-bit chunks of the state until that runs out and then it would run another permutation for more bits. You could simply fix up the API on any of these. – sh1 Jun 18 '13 at 20:25
3 Answers
http://burtleburtle.net/bob/rand/smallprng.html
That is small (128 bits of state) and fast and passes every general purpose statistical test available at this time. Every other PRNG linked to in the responses here so far fails tests rapid - the MWC-based PRNG fail many many tests, while SFMT fails only binary matrix rank / linear complexity type tests.
As others have said, to get 128 bits simply concatenate sequential 32 bit outputs. Do not forcibly extract more bits from a PRNGs state that its normal output function yields - that will generally degrade output quality, sometime by a large amount.

- 418
- 5
- 6
You should try SFMT: SIMD-oriented Fast Mersenne Twister.
This PRNG has been designed to produce 128-bit integers, by taking advantage of vector instructions offered by processors.
For more information about this PRNG, please have a look at another post I answered to by advising SFMT: best pseudo random number generator
For a complete description, see the official page, where you can also download SFMT: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html

- 1
- 1

- 5,721
- 4
- 31
- 50
If simplicity is your top priority, look at the generator in this article. The heart of the generator is just two lines of code. It's not state-of-the-art like Mersenne Twister, but it is simpler and still has good statistical properties.

- 29,517
- 10
- 67
- 94
-
Your MWC implementation does not fulfill @Dan's requirement: he needs a PRNG capable of producing 128-/256-bit numbers. – jopasserat Jun 12 '11 at 19:44