Set seeds for random generator for sensor noise?

Discussion in 'Simulation' started by tor, Feb 4, 2018.

  1. tor

    tor

    Hi Emo:

    I am using the framepos sensor (and mjpro150 linux)
    I have set noise greater than 0 and enabled sensornoise flag in the model file.

    My question is:
    How to set the seed for the random number generator that produces the sensor noise?

    I have tried to use: `srand(someSeed)`,
    but the sequence of sensor noise always the same, no matter what someSeed is.
    It seems that somehow the seed for sensor noise has been fixed somewhere, cmiiw.
    If using `std::default_random_engine generator (someSeed);`, where to put the generator?
    Interestingly, using `mju_standardNormal()` and `srand(someSeed)` works like a charm.
    What do you think?

    I do appreciate your time and attention.
    Thank you,
    tor
     
    Last edited: Feb 5, 2018
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    The compiler calls srand(123) to keep noise sequences reproducible (one can generate random textures and we want them to be the same every time).

    The sensor noise model uses mju_standardNormal(), which in turn calls rand() without resetting the seed.

    So, the trick is to set your custom seed with srand() AFTER the compiler is called (which is done automatically when an XML model is loaded).

    The C++ random number generators are not used; the entire MuJoCo runtime is written in C.