Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Real Random with Tiny

Discussion in 'Project Tiny' started by egonaraujo, Oct 8, 2019.

  1. egonaraujo

    egonaraujo

    Joined:
    Jan 21, 2015
    Posts:
    11
    Hello all,

    I am trying to make a game in Tiny, but I cannot get random to work properly...

    The only way we have to do this, in the sample projects, is like:
    Code (CSharp):
    1. Random _random;
    2.  
    3. public override OnCreate(){
    4.     _random = new Random();
    5.     _random = InitState();
    6. }
    Inside InitState, the tooltip says that the seed is `1851936439U`, this leads to the same numbers across different plays (and in my case, a quite interesting 'bug', I only spawn 2 objects, on 2 different positions. They are different random objects so obj1 always spawn at position1, and obj2 always spawns at position2)

    Only way to overcome this is by setting the seed by hand, but that still makes the game play exactly the same across different plays...

    I tried to initialize using the Framecount, using the InputSystem, and other solutions that do not work because they are not available at `OnCreate()` time.

    Is there a way to get a different pseudo-random seed every time? Like system.Clock(), or system.DateTime(), or mouse.Position() or something?

    P.S.: I know that true random is not yet possible, but maybe getting random from the OS (like linux /random) or the time in seconds that the player is playing would be really helpful