Description
In the use of the system provided by the random random number produced, often will be consistent with the last random number, it is very embarrassing, how to produce a different random number with the last. Very simple (⊙o⊙) Oh ... Code Show:
Using Unityengine;
Using System.Collections;
The public class Random:monobehaviour
{
///finally outputs a random number that is different from the last random number
int getrangenum = 0;
Random numbers randomly generated each time, used to compare the last to the
int rangeradomnum = 0;
Used to calculate the number of each output, easy to observe
int numcount = 0;
Use this for initialization
void Start ()
{
}
//Update are called once per frame
void Update () c15/>{
if (input.getmousebuttondown (0))
{
numcount++;
Do
{
rangeradomnum = random.range (0, 5);
}
while (Getrangenum = = rangeradomnum);
Getrangenum = Rangeradomnum;
Debug.Log ("First" + numcount.tostring () + "random number obtained:" + getrangenum);
}}
The test is as follows: