Unity uses random to generate random numbers that are inconsistent with the last time _random

Source: Internet
Author: User
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:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.