Search Unity

There is no way Random.Range is truly Random

Discussion in 'Getting Started' started by smitsc, Apr 7, 2015.

  1. smitsc

    smitsc

    Joined:
    Mar 4, 2014
    Posts:
    4
    endVector[0] = (Vector3(315,108,-110));
    endVector[1] = (Vector3(45,72,63));
    endVector[2] = (Vector3(-20,0,45));
    endVector[3] = (Vector3(-45,-105,23));
    endVector[4] = (Vector3(45,73,-25));
    endVector[5] = (Vector3(-45,-107,113));


    endCube.Clear();
    for (var i = 0; i < 6; i++)
    {
    for (var j = 0; j < (9 - aSides); j++)
    {
    endCube.Push(endVector);
    }
    }

    var SpinCntr : int = 0;
    var max : int = endCube.length;
    while (SpinCntr < 10)
    {
    cube.transform.rotation = Random.rotation;
    yield WaitForSeconds(.08);
    SpinCntr++;
    }

    var id = Random.Range(0,max);
    cube.transform.eulerAngles = endCube[id];
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Use code tags when posting code. I have no idea what your question actually is, though. No computer can generate "truly" random numbers—they are always deterministic—but UnityEngine.Random uses Marsaglia's Xorshift 128 algorithm, which is quite high quality. If you don't set the seed, it uses the current ticks in some way, so for all practical purposes it's truly random.

    --Eric
     
    kdubnz, Kondor0 and Kiwasi like this.
  3. smitsc

    smitsc

    Joined:
    Mar 4, 2014
    Posts:
    4
    Am I using the Random.Range (2nd to last line, javascript) correctly?
    I saw it return the same result 4 times in a row from a list (array) of almost 50 items??
    How do I use code tags?
     
  4. kdubnz

    kdubnz

    Joined:
    Apr 19, 2014
    Posts:
    177