• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Question about Random numbers PART 2

## Recommended Posts

Dark Star    100
Hi all, again, I have discovered how the rand() function in C/C++ works, well in the GNU C/C++ anyway (I use DJGPP) Its function is
  int rand(void) { randSeed = (69069 * randSeed+1); return randSeed & 0x7fff; } // the srand function is defined as: void srand(unsigned seed) { randSeed = seed; } 
what I want to know from yesturdays post about random numbers is that from this formula used in rand can it be reversed to give you the last version of randSeed? I''ll try to make this more clear because I am kinda confusing myself here. Say for example if randSeed was 356456 before the line in rand() return randSeed & 0x7fff; and that maybe gave 563464 (made up value!) could I reverse the statement randSeed & 0x7fff; to give me the value of randSeed before it hit that line so that I can rearrange this formula randSeed=(69069 * randSeed + 1); so that I can get the value of randSeed before it hit this line too. I know this all sounds weird and I can''t really go into why I wanna play around with random numbers but it is a secret project I am working on to some how revolutionise something in computing. (One clue, Winzip''s job, don''t ask how cos I dont fully know, but I kinda found a link between a new file format for compressed files and random numbers) Can you also tell me if the rand() function given its definition that I have researched and written for you can produce any set of random numbers in the world or is it only good for producing deterministic numbers that never repeat so often, you see I would like numbers as realistic as for example picking 12 numbers out of a hat (numbers from 1 to 12 and on every pick its put back and the hat is shuffled) and managing to some how pick a sequence maybe like: 1,4,4,4,4,4,5,2,6,12,5,4,2,7,9 what I mean is can rand() function ever produce something like this because in reality, someone may pick out the number 4, from a hat 5 times in a row. Are there any random functions or algorithms that can produce random numbers as real as the set above. This is really important to me because once I can find a function that produces life like random numbers not deterministic numbers that will never look like the number set above then I can work on how to derive the seed back from the last random number all the way to the beginning so that I can derive the initial seed that sparked the entire random sequence. This is a windful, I know and some how doubt this can ever work, but if it can believe me, it would revolutionise something big time !!!!!! Any Help is good help Dark Star

##### Share on other sites
Ironblayde    130
So what you''re asking is, from the value (randSeed & 0x7fff), can you recover the value of randSeed? If that is your question, the answer is unfortunately no. That bitwise AND serves to report only the lower 15 bits of randSeed. Any higher bits are simply discarded, so there is no way to recover what they were.

The example you provided can be generated by a random number function provided you are not using its full range. That is, if you''re getting random numbers between 1 and 12 by taking a large random number modulo 12, plus 1, then repeats can certainly occur.

-Ironblayde
Aeon Software

Down with Tiberia!
"All your women are belong to me." - Nekrophidius

##### Share on other sites
MfA    122
One random number generator is not a model for another, sure if you have an ideal pseudo random number generator (obviously dont exist) you can in theory encode any sequence of numbers as an offset and seed for that generator... but what will you find is that it was a waste of time because on average the entropy in the offset and seed will be the same as the sequence''s you were trying to encode.

Try reading some of Charles Blooms stuff (and compression&math in general perhaps) and his explanation of why there are no magic compressors.