Search Unity

Random.Range() returns the same for copied objects?

Discussion in 'Scripting' started by Lostlogic, Nov 14, 2009.

  1. Lostlogic

    Lostlogic

    Joined:
    Sep 6, 2009
    Posts:
    693
    I have 3 objects that are to spin for different lengths of time but they all use the same script.

    In the Start() I do a Random.seed = # (which I set in the editor to 100, 23467, and 194858) and for the random call I do a Random.Range(0,10).

    The problem is that they all spin for the same length of time. Any ideas how to get different #s from each Random.Range() call?
     
  2. tomvds

    tomvds

    Joined:
    Oct 10, 2008
    Posts:
    1,028
    Are you setting the seed in Start and then use Random.Range in Update or some other function that is not Start? Because in that case, Random will just use the seed of the object that happened to be last in line to execute Start. To solve this, set the seed in the same function where you use Random.Range or generate and store the random number in Start.

    If you did both set the seed and get the random number in Start, the problem is something else. In that case, posting your code in Start will give us some more information on what might be going wrong.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You shouldn't be using Random.seed in the first place, unless you actually want the results to be repeatable.

    --Eric
     
  4. Lostlogic

    Lostlogic

    Joined:
    Sep 6, 2009
    Posts:
    693
    I tried it without using Seed and it repeated, which is why I tried the seed method. I call .seed in my Start() and call Random.Range() in my Update function. I'll keep plugging away to see whats going on.