设置随机种子,让每次随机结果一致。 

using UnityEngine;
using UnityEditor;
using NUnit.Framework;

public class TestRandom
{
    System.Random random;
    [Test]
    public void EditorTest()
    {
        //设置随机数种子
        random = new System.Random(1000);
        string str = "";
        //for (int i = 0; i < 10; i++)
        //{
        //    str += Random.Range(1, 100) + ",";
        //}
        for (int i = 0; i < 10; i++)
        {
            str += RandomRange(1, 100)+",";
        }
        Debug.Log(str);
    }

    /// <summary>
    /// 随机整型
    /// </summary>
    /// <param name="min"></param>
    /// <param name="max"></param>
    /// <returns></returns>
    public int RandomRange(int min, int max)
    {
        return random.Next(min, max);
    }

    /// <summary>
    /// 随机浮点数
    /// </summary>
    /// <param name="min"></param>
    /// <param name="max"></param>
    /// <returns></returns>
    public float RandomRange(float min, float max)
    {
        var r = random.NextDouble();
        return (float)(r * (max - min) + min);
    }

}
04-23 10:48