How to repeat a random result

Hi, guys:

Apparently I have the opposite problem to everyone else: I want to repeat a random result.

My code is this:

void random_gen(){
	for (int i=0;i<4000;i++){
		Random.seed=3;
		int posRand = Random.Range(0,2000);
		array1*=posRand;*
  •   }*
    
  • }*
    But array1 gets different values all the time.
    I dont want to generate 4000 numbers by hand and write it in script definitions, but i want the same array result in every run of the game. Do you figure out something?

You can always use the .NET/Mono [Random][1] class.

using System.Random;

// ...

void random_gen() {
    for (int i=0; i < 4000; i++) {
       System.Random random = new System.Random(3);
       array1 *= random.Next(2000);*

}
}
[1]: http://msdn.microsoft.com/en-us/library/system.random(v=vs.110).aspx

You are changing the seed every loop. Take Random.seed=3; and pull it out of the loop, and make 3 a bigger number, just put a constant in it (Not too large though). Another option is a custom number generator. Take this for example:

void random_gen() {
  for( int i = 0; i < 4000; i++ ) {
    uint Seed = (uint)(bignum + bignum*i);
    Seed = (uint)(Mathf.Abs((69621*Seed)% 2000 ));
    array *= (int)Seed;*

}
}
bignum is just your seed, which can be an arbitrary number.

Sorry, i forgot to update the script (i had it copied). My code works with seed inside and outside the loop.