QRandomGenerator ULLONG_MAX
-
Hello,
generating a random integer between 0 and
ULONGLONG_MAX
does not work.QRandomGenerator rng; //works quint16 x = rng.bounded(0, USHRT_MAX); QByteArray xHex = QString::number(x, 16).toUpper().toLocal8Bit(); // does not work quint64 y = rng.bounded(quint64(0), quint64(18446744073709551615)); quint64 y = rng.bounded(quint64(0), ULLONG_MAX); quint64 y = rng.bounded(0, ULLONG_MAX); QByteArray yHex = QString::number(y, 16).toUpper().toLocal8Bit(); // works quint16 z = rng.bounded(0, USHRT_MAX); QByteArray zHex = QString::number(z, 16).toUpper().toLocal8Bit();
Anyone know how to make this work?
-
@Redman
In what sense "does not work"? Generates a compilation error? Does not return what you expect it to at runtime?I was not able to find
ULONGLONG_MAX
(other than in Boost). Your code does not use such a symbol.ULLONG_MAX
does exist and seems to be "unsigned long long int", 64-bit. The (only) overload I see matching this is quint64 QRandomGenerator::bounded(unsigned int lowest, quint64 highest). Make sure you use this overload. I don't see any overload which takesquint64
for both lower & upper bounds.quint64 y = rng.bounded(0, ULLONG_MAX);
looks like it should match, trystatic_cast<>
ing the parameters to make sure this one is being used?And you should also read the documentation carefully:
"Note that this function cannot be used to obtain values in the full 64-bit range of quint64. Instead, use generate64()."
-
Hello,
generating a random integer between 0 and
ULONGLONG_MAX
does not work.QRandomGenerator rng; //works quint16 x = rng.bounded(0, USHRT_MAX); QByteArray xHex = QString::number(x, 16).toUpper().toLocal8Bit(); // does not work quint64 y = rng.bounded(quint64(0), quint64(18446744073709551615)); quint64 y = rng.bounded(quint64(0), ULLONG_MAX); quint64 y = rng.bounded(0, ULLONG_MAX); QByteArray yHex = QString::number(y, 16).toUpper().toLocal8Bit(); // works quint16 z = rng.bounded(0, USHRT_MAX); QByteArray zHex = QString::number(z, 16).toUpper().toLocal8Bit();
Anyone know how to make this work?
@Redman said in QRandomGenerator ULLONG_MAX:
does not work.
Apart fromt he fact that the code does not compile this is not an useful error description...
-
Hello,
generating a random integer between 0 and
ULONGLONG_MAX
does not work.QRandomGenerator rng; //works quint16 x = rng.bounded(0, USHRT_MAX); QByteArray xHex = QString::number(x, 16).toUpper().toLocal8Bit(); // does not work quint64 y = rng.bounded(quint64(0), quint64(18446744073709551615)); quint64 y = rng.bounded(quint64(0), ULLONG_MAX); quint64 y = rng.bounded(0, ULLONG_MAX); QByteArray yHex = QString::number(y, 16).toUpper().toLocal8Bit(); // works quint16 z = rng.bounded(0, USHRT_MAX); QByteArray zHex = QString::number(z, 16).toUpper().toLocal8Bit();
Anyone know how to make this work?
@Redman
In what sense "does not work"? Generates a compilation error? Does not return what you expect it to at runtime?I was not able to find
ULONGLONG_MAX
(other than in Boost). Your code does not use such a symbol.ULLONG_MAX
does exist and seems to be "unsigned long long int", 64-bit. The (only) overload I see matching this is quint64 QRandomGenerator::bounded(unsigned int lowest, quint64 highest). Make sure you use this overload. I don't see any overload which takesquint64
for both lower & upper bounds.quint64 y = rng.bounded(0, ULLONG_MAX);
looks like it should match, trystatic_cast<>
ing the parameters to make sure this one is being used? -
@Redman
In what sense "does not work"? Generates a compilation error? Does not return what you expect it to at runtime?I was not able to find
ULONGLONG_MAX
(other than in Boost). Your code does not use such a symbol.ULLONG_MAX
does exist and seems to be "unsigned long long int", 64-bit. The (only) overload I see matching this is quint64 QRandomGenerator::bounded(unsigned int lowest, quint64 highest). Make sure you use this overload. I don't see any overload which takesquint64
for both lower & upper bounds.quint64 y = rng.bounded(0, ULLONG_MAX);
looks like it should match, trystatic_cast<>
ing the parameters to make sure this one is being used?And you should also read the documentation carefully:
"Note that this function cannot be used to obtain values in the full 64-bit range of quint64. Instead, use generate64()."
-
@Redman
In what sense "does not work"? Generates a compilation error? Does not return what you expect it to at runtime?I was not able to find
ULONGLONG_MAX
(other than in Boost). Your code does not use such a symbol.ULLONG_MAX
does exist and seems to be "unsigned long long int", 64-bit. The (only) overload I see matching this is quint64 QRandomGenerator::bounded(unsigned int lowest, quint64 highest). Make sure you use this overload. I don't see any overload which takesquint64
for both lower & upper bounds.quint64 y = rng.bounded(0, ULLONG_MAX);
looks like it should match, trystatic_cast<>
ing the parameters to make sure this one is being used? -