生成具有256个随机位的数字的最佳方法? [英] Best method of generating a number with 256 random bits?

查看:578
本文介绍了生成具有256个随机位的数字的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

生成具有256个随机位的数字的最佳方法是什么?

串联随机字节有效吗?


byte[] data = new byte[32];
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetNonZeroBytes(data); // should include zero bytes?
string number = BitConverter.ToString(data, 0).Replace("-", "");

此外,使用这些数字的非重复分类一副纸牌是否合适?

解决方案

是否可以连接随机字节取决于您使用的随机数生成器.一些随机数生成器表现出串行相关性.对于这些随机数生成器,连接是不好的.

如果您出于冷冻照相目的使用这些随机数,则应查看 Blum Blum Shub .否则,请查看 Merenne Twister .

要对有限集合进行混排,请查看 Fisher-Yates混排./p>

What is the best method of generating a number with 256 random bits?

Does concatenating random bytes work?


byte[] data = new byte[32];
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetNonZeroBytes(data); // should include zero bytes?
string number = BitConverter.ToString(data, 0).Replace("-", "");

Further more, would it be appropriate to sort a deck of cards using non-duplicates of these numbers?

解决方案

Whether or not you can concatenate random bytes depends on the random number generator that you are using. Some random number generators exhibit serial correlation. For these random number generators, concatenating would be bad.

If you are using these random numbers for crypotgraphic purposes, you should look at Blum Blum Shub. Otherwise, look at the Mersenne Twister.

For shuffling a finite set, look at the Fisher-Yates shuffle.

这篇关于生成具有256个随机位的数字的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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