我创造了一个骰子游戏,骰子基于百分位数,1-100.
public static void Roll()
{
Random rand = new Random((int)DateTime.Now.Ticks);
return rand.Next(1, 100);
}
Run Code Online (Sandbox Code Playgroud)
但我不认为这是基于当前时间的真实随机.
如果我做
for (int i = 0; i < 5; i++)
{
Console.WriteLine("#" + i + " " + Roll());
}
Run Code Online (Sandbox Code Playgroud)
它们都是相同的值,因为它DateTime.Now.Ticks没有改变,它播种的数字相同.
我想我可以生成一个新的随机种子,如果由于当前时间种子是相同的,但它不像一个诚实的"重新滚动"
我应该怎么做才能尝试复制接近真实/诚实的骰子卷?我应该使用RNGCryptoServiceProvider该类来生成卷吗?
我正在研究一个神经网络项目,我有两个这样的类:
public class Net
{
// Net object is made of neurons
public List<Neuron> Neurons = new List<Neuron>();
// neurons are created in Net class constructor
public Net(int neuronCount, int neuronInputs)
{
for (int n = 0; n < neuronCount; n++)
{
Neurons.Add(new Neuron(n, neuronInputs));
}
}
}
public class Neuron
{
public int index; // neuron has index
public List<double> weights = new List<double>(); // and list of weights
// Neuron constructor is supposed to add random weights to …Run Code Online (Sandbox Code Playgroud)