本文介绍了为什么不允许`std :: uniform_int_distribution< uint8_t>`和`std :: uniform_int_distribution< int8_t>`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我不在乎范围,我可以只屏蔽一个更大的类型的位以产生随机数。如果不是,它更复杂。为什么默认情况下不提供字节类型?

If I don't care about the range, I can just mask off the bits of a larger type to generate random numbers. If not, it's more complex. Why aren't the byte types provided just by default?

推荐答案

此,并且其中包括:

建议的解决方案是更改限制以允许标准整数类型:

The proposed resolution is to change the restriction to allow standard integer types:

和:

虽然不是 uint8_t ,但可以获得

This gets you unsigned / signed char although not uint8_t or int8_t but they are likely equivalent. Extended integral types were exluded to simplify the wording and maximize consensus:

注意,这不包括 char 因为它是实现定义 char 是否已签名。

Note, this excludes char since it is implementation defined whether char is signed or not.

标准讨论列表 a>。

Jonathan Wakely指出这个建议有争议,并评论他上次讨论的笔记包括:

Jonathan Wakely notes this proposal is controversial and commented that his notes from the last discussion include the following:

他建议为 random_device 添加一个成员以提供单个字节像一个合理的选择。

He suggests adding a member to random_device to provide single bytes, which is seems like a reasonable alternative.

这篇关于为什么不允许`std :: uniform_int_distribution< uint8_t>`和`std :: uniform_int_distribution< int8_t>`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!