I'd like to generate a random number of reasonably arbitrary length in C++. By "reasonably arbitary" I mean limited by speed and memory of the host computer.
Let's assume:
I want to sample a decimal number (base 10) of length ceil(log10(MY_CUSTOM_RAND_MAX))
from 0
to 10^(ceil(log10(MY_CUSTOM_RAND_MAX))+1)-1
I have a vector<char>
The length of vector<char>
is ceil(log10(MY_CUSTOM_RAND_MAX))
Each char
is really an integer, a random number between 0 and 9, picked with rand()
or similar methods
If I use std::random_shuffle
to shuffle the vector, I could iterate through each element from the end, multiplying by incremented powers of ten to convert it to unsigned long long
or whatever that gets mapped to my final range.
I don't know if there are problems with std::random_shuffle
in terms of how random it is or isn't, particularly when also picking a sequence of rand()
results to populate the vector<char>
.
How sketchy is std::random_shuffle
for generating a random number of arbitrary length in this manner, in a quantifiable sense?
(I realize that there is a library in Boost for making random int
numbers. It's not clear what the range limitations are, but it looks like MAX_INT
. That said, I realize that said library exists. This is more of a general question about this part of the STL in the generation of an arbitrarily large random number. Thanks in advance for focusing your answers on this part.)
I'm slightly unclear as to the focus of this question, but I'll try to answer it from a few different angles:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.