views:

111

answers:

4

first off, is there a such thing as a random access random number generator, where you could not only sequentially generate random numbers as we're all used to, assuming rand100() always generates a value from 0-100:

for (int i=0;i<5;i++)
   print rand100()

output: 
14
75
36
22
67

but also randomly access any random value like:

rand100(0) would output 14 as long as you didn't change the seed

rand100(3) would always output 22

rand100(4) would always output 67

and so on...

I've actually found an open-source generator algorithm that does this, but you cannot change the seed. I know that pseudorandomness is a complex field; I wouldn't know how to alter it to add that functionality.

Is there a seedable random access random number generator, preferably open source? or is there a better term for this I can google for more information?

if not, part 2 of my question would be, is there any reliably random open source conventional seedable pseudorandom number generator so I could port it to multiple platforms/languages while retaining a consistent sequence of values for each platform for any given seed?

+3  A: 

I've not heard of anything like that, but it seems to me you could take use a decent hash and write a wrapper function that takes a seed value and your 'index', and runs them through the hash function. I'm not sure of the randomness of the bits output by various cryptographic hash functions, but I imagine that someone has taken a look at that.

Michael Burr
I agree -- use the built in randomness features of your language, and build a data structure around it, and use that like a wrapper.
Jared P
A: 

I haven't seen one quite like that, but it would be fairly easy to manage in most cases. A PRNG normally takes a seed, and the sequence produced after a given seed is normally fixed, so what you want is basically something that seeds the generator, then return the output.

Jerry Coffin
A: 

All the generators I'm aware of are iterative. So, any 'random access' would involve calculating all the values from the first to the one you ask for.

The closest you could come is to take a fixed seed, hash it, and then hash the index value, using something that mixes really enthusiastically.

Or generate a long list of them and store it.

bmargulies
+1  A: 

Thanks for all the replies, and also, for anyone who might happen upon this asking a similar question, I found a solution that isn't exactly what I asked for, but fits the bill for my purposes.

It is a perlin noise class that can be found here. I'm not sure how computationally complex this is relative to a conventional random number generator, which is a concern, since one of the planned platforms is Android. Also, perlin noise isn't the same thing as pseudorandomness, but from what I can tell, a high octave and/or frequency value should provide suitable randomness for non-cryptographic purposes, where the statistical level of true randomness isn't as important as the mere appearance of randomness.

This solution allows seeding, and also allows sampling a random set from any point, in other words, random access randomness.

here's an example set of regular c++ randomness (rand%200) on the left column for comparison, and perlin noise (with the equivalent of %200) on the right:

91 , 100
48 , 97
5 , 90
93 , 76
197 , 100
97 , 114
132 , 46
190 , 67
118 , 103
78 , 96
143 , 110
187 , 108
139 , 79
69 , 58
156 , 81
123 , 128
84 , 98
15 , 105
178 , 117
10 , 82
13 , 110
182 , 56
10 , 96
144 , 64
133 , 105

both were seeded to 0

the parameters for the perlin noise were

octaves = 8
amplitude = 100 
frequency = 9999
width/height = 10000,100

the sequential sampling order for the perlin noise was simply

for (int i=0;i<24;i++)
    floor(Get(i,i)+100);
//amplitude 100 generates noise between -100 and 100, 
//so adding 100 generates between 0 and 200
lucid
Thanks for sharing
unomi