Repeatable seeded pseudorandomness
Posted: 14 Nov 2018, 18:36
If one wants to insert deliberate randomness into a simulation using (for example) CompassAngleToDriveAlong=math.random(-180,180) but one wants the series of directions chosen by this function to be random but repeatable then in lua one would typically set math.randomseed(KnownConstantValue) beforehand. When one wanted a different random sequence in a future run of the simulation one would change the constant's value. But I am having trouble doing this. V-REP seems to automatically call something like math.randomseed( os.time() ) which causes the random seeds to be wiped over and non-repeatable randomness to return. When I run simulations where I do not use any randomness in the robot controllers I find them perfectly repeatable each time I run them, while true randomness may be used in the physics engine somewhere the results still end up broadly the same for my types of situation.
My understanding is that V-REP seems to use the same randomness to power the physics engine and to satisfy any calls of math.random(lower,upper) used in controllers.
Can anything be done in a future release such that setting math.randomseed(KnownConstantValue) within the controller (non-threaded) child scripts of each robot (each robot that uses math.randomseed anyway) in the scene during the initialisation step leads to repeatable randomness. If one uses multiple similar robots and wants them to have independent randomness one could just give them each a different seed, but when you ran the same sim with the seed you would have certainty that ,except for little differences tyhat may result in the physics engine calculations, one would get the same random sequences and repeatable results. In the swarms/modular/evolvable robotics fields we often like to run loads of repetitions of a scenario with a different random seed each time, but with the knowledge that if we see something intriguing happen for a specific random seed value we can go back to that random seed value and get exactly the same sim to run again. Things are a bit tricky when the lack of a way to set random seeds as one either has to go through the effort of creating a random sequence in an external text file for controllers to read from (and get the same random sequence each time unless you change the file contents) or one can do genuine randomness but not be able to repeat a particularly interesting experiment to mroe carefully investigate why a certain result happened.
Thanks
My understanding is that V-REP seems to use the same randomness to power the physics engine and to satisfy any calls of math.random(lower,upper) used in controllers.
Can anything be done in a future release such that setting math.randomseed(KnownConstantValue) within the controller (non-threaded) child scripts of each robot (each robot that uses math.randomseed anyway) in the scene during the initialisation step leads to repeatable randomness. If one uses multiple similar robots and wants them to have independent randomness one could just give them each a different seed, but when you ran the same sim with the seed you would have certainty that ,except for little differences tyhat may result in the physics engine calculations, one would get the same random sequences and repeatable results. In the swarms/modular/evolvable robotics fields we often like to run loads of repetitions of a scenario with a different random seed each time, but with the knowledge that if we see something intriguing happen for a specific random seed value we can go back to that random seed value and get exactly the same sim to run again. Things are a bit tricky when the lack of a way to set random seeds as one either has to go through the effort of creating a random sequence in an external text file for controllers to read from (and get the same random sequence each time unless you change the file contents) or one can do genuine randomness but not be able to repeat a particularly interesting experiment to mroe carefully investigate why a certain result happened.
Thanks