64位强随机函数 [英] 64 bit Strong Random function

查看:79
本文介绍了64位强随机函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




在上一个问题中,有人建议使用

System.Security.Cryptography来填充具有强随机字节的数组。


它有效但我当然不能指定最大值..我通过

解决了它后来删除了所有''高于最大值'的值,但是这不是高效的,也不是快的。


任何人都可以指着我一个C# - 可用的随机数生成器至少

52位?并且比默认的System.Random更随机(在线测试失败了几个

)。


我需要它用于蒙特卡罗类型的模拟与甲板卡(因此

52位)。


谢谢!

解决方案

< blockquote>你好


您仍然可以使用加密

除了删除高于最大值的数字,您还可以执行以下操作:

randomNumber = randomNumber%maxValue; //最小值为零


如果你有最小值

randomNumber = randomNumber%(maxValue - minValue)+ minValue;


第一种情况与第二种情况相同,minValue = 0;

生成的数字小于maxValue且大于或等于minValue


minValue< = randomNumber< maxValue

祝你好运

谢里夫


" Stu Banter" < X2 ************** @ westerterp.com>在消息中写道

新闻:3f *********************** @ dreader3.news.xs4al l.nl ... < blockquote class =post_quotes>

在上一个问题中,有人建议使用
System.Security.Cryptography来填充具有强随机字节的数组。
它有效,但我不能指定当然的最大值..我通过
随后删除所有''高于最大''值来解决它,但这不是有效的,也不是快的。

任何可以指向C#-usable随机数发生器的人都只需
至少52位?并且比默认的System.Random更随机(在线测试失败了几个。)

我需要它用于蒙特卡罗类型的模拟与一副牌(因此
52位)。

谢谢!



你好


您仍然可以使用加密技术

您可以执行以下操作,而不是删除高于最大值的数字:

randomNumber = randomNumber%maxValue; //最小值为零


如果你有最小值

randomNumber = randomNumber%(maxValue - minValue)+ minValue;


第一种情况与第二种情况相同,minValue = 0;

生成的数字小于maxValue且大于或等于minValue


minValue< = randomNumber< maxValue

祝你好运

谢里夫


" Stu Banter" < X2 ************** @ westerterp.com>在消息中写道

新闻:3f *********************** @ dreader3.news.xs4al l.nl ... < blockquote class =post_quotes>

在上一个问题中,有人建议使用
System.Security.Cryptography来填充具有强随机字节的数组。
它有效,但我不能指定当然的最大值..我通过
随后删除所有''高于最大''值来解决它,但这不是有效的,也不是快的。

任何可以指向C#-usable随机数发生器的人都只需
至少52位?并且比默认的System.Random更随机(在线测试失败了几个。)

我需要它用于蒙特卡罗类型的模拟与一副牌(因此
52位)。

谢谢!



嗨Stu,


出于兴趣,您如何使用密码学获取随机的

数字?然后你又和他们一起做什么?


我问的原因是你提到了比特 - 确切地说是52 - 所以我是

想知道这是否有用:


字节aBytes [8];

Security.Cryptography.RNGCryptoServiceProvider oRndGen;

oRndGen = new Security.Cryptography.RNGCryptoServiceProvider();

oRndGen.GetBytes(aBytes);

BitArray Bits = new BitArray(aBytes);

Bits .Length = 52;


问候,

Fergus


Hi,

On a previous question someone recommended using the
System.Security.Cryptography to fill an array with strong random bytes.

It works but I can''t specify the max value of course.. I solved it by
subsequently removing all ''higher than max'' values, but this is not
efficient, nor fast.

Anyone who can point me to a C#-usable Random Number Generator with at least
52 bits? And more random than the default System.Random (fails several of
the online tests).

I need it for Monte Carlo type of simulations with a deck of cards (hence
the 52 bits).

Thanks!

解决方案

Hello

You can still use cryptography
Instead of removing numbers higher than max, you can do the following:
randomNumber = randomNumber % maxValue; //min value is zero

if you have a minimum value
randomNumber = randomNumber % (maxValue - minValue) + minValue;

the first case is the same as second case with minValue = 0;
the generated number less then maxValue and greater than or equal minValue

minValue <= randomNumber < maxValue
Best regards
Sherif

"Stu Banter" <x2**************@westerterp.com> wrote in message
news:3f***********************@dreader3.news.xs4al l.nl...

Hi,

On a previous question someone recommended using the
System.Security.Cryptography to fill an array with strong random bytes.

It works but I can''t specify the max value of course.. I solved it by
subsequently removing all ''higher than max'' values, but this is not
efficient, nor fast.

Anyone who can point me to a C#-usable Random Number Generator with at least 52 bits? And more random than the default System.Random (fails several of
the online tests).

I need it for Monte Carlo type of simulations with a deck of cards (hence
the 52 bits).

Thanks!



Hello

You can still use cryptography
Instead of removing numbers higher than max, you can do the following:
randomNumber = randomNumber % maxValue; //min value is zero

if you have a minimum value
randomNumber = randomNumber % (maxValue - minValue) + minValue;

the first case is the same as second case with minValue = 0;
the generated number less then maxValue and greater than or equal minValue

minValue <= randomNumber < maxValue
Best regards
Sherif

"Stu Banter" <x2**************@westerterp.com> wrote in message
news:3f***********************@dreader3.news.xs4al l.nl...

Hi,

On a previous question someone recommended using the
System.Security.Cryptography to fill an array with strong random bytes.

It works but I can''t specify the max value of course.. I solved it by
subsequently removing all ''higher than max'' values, but this is not
efficient, nor fast.

Anyone who can point me to a C#-usable Random Number Generator with at least 52 bits? And more random than the default System.Random (fails several of
the online tests).

I need it for Monte Carlo type of simulations with a deck of cards (hence
the 52 bits).

Thanks!



Hi Stu,

Out of interest, how are you using Cryptography to get your random
numbers? And what are you then doing with them?

The reason I ask is that you mention bits - 52 to be exact - so I''m
wondering whether this might of any use:

byte aBytes [8];
Security.Cryptography.RNGCryptoServiceProvider oRndGen;
oRndGen = new Security.Cryptography.RNGCryptoServiceProvider();
oRndGen.GetBytes (aBytes);
BitArray Bits = new BitArray (aBytes);
Bits.Length = 52;

Regards,
Fergus


这篇关于64位强随机函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆