c# - 使用相同的 System.Random 算法生成线性伪随机数

标签 c# .net algorithm random

有没有什么方法可以在不经过 rnd.NextDouble() 循环的情况下预测 Random 类的一些数量?

我现在正在使用这段代码:

Random rnd = new Random(SOME_STATIC_SEED);

//I need to get the 1000000'th random number:
for (ulong i = 0; i < 1000000; i++) 
//I need to avoid this loop and get the result in a linear time!
{
      rnd.NextDouble();
}
double iNeedThisNumber = rnd.NextDouble();

没有循环我怎么能得到它?我需要使用 .Net 的 System.Random 类的算法给出相同的确切数字!


据称已解决:

这是我的代码!!

public static ulong GetNumberFromSequence(int seq) 
{ 
    Random rnd = new Random(seq); 
    return (ulong)(rnd.NextDouble() * 99999999999999) ^ (ulong)seq; 
}

最佳答案

看看这是否适合你

在随机数生成器中使用所需索引的种子,然后选择第一个生成的数字。

Random rnd = new Random(required_index_as_seed).Next();
double iNeedThisNumber = rnd.NextDouble();

关于c# - 使用相同的 System.Random 算法生成线性伪随机数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8692869/

相关文章:

c# - Crystal Report 不会将数据集放在一起

c# - 从 C# ASP.NET 应用程序进行远程和本地打印

c++ - 需要 Codechef 练习题帮助 - 在阶乘中找到尾随零

algorithm - 一种路径分配程序算法

algorithm - D元堆: Intuition behind parent(int i) and child(int i) function's implementation

c# - 如何对以下列表进行排序

.net - 如何将包含日期的字符串转换为不同的格式?

c# - 动态禁用特定的上下文菜单项

c# - 如果从同一个线程调用 Dispatcher.BeginInvoke 是否会将调用排队?

c# - asp.net 未找到 OpenCV 非托管 DLL