Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Seeding the randomizer?

Discussion in 'Editor & General Support' started by Morgan, Jul 18, 2006.

  1. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    Is there a way I can feed a specific seed to Unity's randomizer? (Which, I assume, uses a time-based seed normally?)

    I want REPEATABLE randomness: so every time I use a given seed, my radomly-placed objects to appear in the same positions. Or change the seed and I get another arrangement--but always reproducible. Ditto for randomly generated terrains or other effects.

    This would be useful for making certain parts of some levels. Random is MUCH quicker than placing thousands of objects by hand... but I want the levels to be the same when re-played.

    (I know that motion and physics-based responses will vary from play to play due to timing, I just want my terrain and random items to start the same each session. Then after level setup I'll probably re-seed using time and/or mouse, so the enemies do not act the same each play.)
     
  2. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    You probably want to use .NET's System.Random class instead of UnityEngine.Random. Check out the Mono documentation on this subject here.
     
  3. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    Thanks - I'll explore that.