简体   繁体   English

unity(C#)随机数批量创建

[英]Unity (C#) random numbers are created in batches

I'm creating 500 random numbers in a Unity project like so:我在 Unity 项目中创建 500 个随机数,如下所示:

int[] random_numbers = new int[500];
for(int i = 0; i < 500; i++) 
{
    random_numbers[i] = UnityEngine.Random.Range(60, 100);
}

The results I get are the numbers seem to be created in batches.我得到的结果是数字似乎是分批创建的。 For example, I will get the number 89 ten times in a row and then the number 95 ten times in a row and so on.例如,我会连续十次得到数字 89,然后连续十次得到数字 95,依此类推。 I don't have a problem with getting the same number, but I can't have them created in large batches like this.获得相同的数字没有问题,但我不能像这样大批量创建它们。

I understand that the Unity random number engine uses the clock to create the number.我了解 Unity 随机数引擎使用时钟来创建数字。 I'm wondering how I can get better quality random numbers?我想知道如何获得质量更好的随机数?

Numbers should be random.数字应该是随机的。 Make sure to have "Collapse" disabled in the console:确保在控制台中禁用“折叠”:

在此处输入图像描述

在此处输入图像描述

Or save it in a public or [Serialized] field and view it in the Inspector.或者将其保存在公共[序列化]字段中并在检查器中查看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM