gpt4 book ai didi

c# - 相同的随机值

转载 作者:行者123 更新时间:2023-11-30 22:33:08 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Random number generator not working the way I had planned (C#)
Why does it appear that my random number generator isn't random in C#?

我对随机值有疑问

        int weight = 0;
Random random = new Random();
for (int i = 0; i < entriesCount; i++)
{
weight = random.Next(10);
this.weights[i] = weight;
}

此代码在我的对象的构造函数中。我创建了 3 个不同的对象

Object object1 = new Object(2);
Object object2 = new Object(2);
Object object3 = new Object(2);

对于每个对象,我都会得到相同的随机值,例如:4、5 | 4, 5 | 4, 5

每次我以相同的顺序获得相同的值。我不明白为什么>请帮忙

最好的问候,大卫

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com