Random Number Generator

Hello my question is how to code a random number generator. what im trying to do is make it so that when my heroe gets within one square of an enemy (which will be represented as a “?” until this happens) that the tile will randomly pick a number between 1 and 254 and a monster will be accompanied with that number and when the number is picked the tile will change into the monster. how could i do this, thanks in advance!

var number = Random.Range(1,254);

to detect wether the player is within one square of the question mark you can either use OnTriggerEnter (if you have a trigger on the game object) or you can calculate the distance between the objects and then if(distance < 1) and trow the random generator in that.

then do what ever you want with that number

int seedArray;
List seedList = new List();
for(int i = 0;i<1000;i++){
int newSeed = Random.Range(0,64)+Random.Range(0,64)+Random.Range(0,64)+
Random.Range(0,64)+Random.Range(0,64)+Random.Range(0,64)+Random.Range(0,64);
seedList.Add(newSeed);
}
seedArray = seedList.ToArray);

do not forget to use System.Linq; to convert from a generic list to an array. by using this as a source, it should be possible to create a list of seeds that can be used to create a more randomized feel from a Psuedorandom number generator

If you want truly random numbers, This is what I use. I generated 250 different numbers.

Random.seed = (Random.Range(Random.Range(Random.Range(Random.Range(0, 25), Random.Range(324, 5673)), Random.Range(Random.Range(53, 2378), Random.Range(50, 423))), Random.Range(Random.Range(Random.Range(23, 2354), Random.Range(1, 3456)), Random.Range(Random.Range(7, 32421), Random.Range(8, 23472)))));

Then use

int myInt;
myInt = Random.Range(0,25);

Just a tiny bit in excess, but it will give you a new number each time.
Try not to call it too many times though :smiley:

  • CausticLasagne