Determine what the random seed was?
Posted: Fri May 14, 2010 11:56 am
When the PureBasic Random() is used it generates its own random seed, is there a way to determine what the seed was?
http://www.purebasic.com
https://www.purebasic.fr/english/
Then again this may be too much of a change for the next beta or RC.Result=RandomSeed([Value])
Description
Changes the actual random number seed for the values returned with Random().
If no Value is given then PureBasic will generate a new seed using it's internal method
Result is the seed that was created or set.
Note: each time a program is started, a new seed is generated, therefore RandomSeed() is useful only when the goal is to generate the same random numbers in the same order every time the program is executed.
Code: Select all
#Max = 2147483647
seed = Random(#Max)
Debug seed
RandomSeed(seed)
; Here goes the main code ...Oh you should have said that. The seed is a long, which means you can try all possible seeds and see which seed generates the wanted random numbers.SFSxOI wrote:I wanted to make sure there WAS NOT a way to retrieve the seed used in Random() for the random number produced.
With CryptRandom() there is not state information in the calling process. The generator's internal state as well as the entropy pool for re-seeding are all managed by the kernel. You cannot get to that without root access. However, if an attacker has full access to your program while you generate the numbers then you have lost the battle anyway, as he could just hook the API functions for the random number generation and feed you whatever data he wants. But for most practical applications this scenario only has to be considered by the most paranoid (and even then, just run your program with proper access rights and it is solved)Rescator wrote:You might reduce that risk by running it as admin and just handing the random number to the user level program thus keeping the seed in the running admin exe, on Vista and Win7 if UAC etc is not messed with (turned off etc) that should prevent a user level program from getting the seed from the admin level program.
Don't take my word for it, test it. Most likely the API function to get the process memory will given an access error or similar.