I don't understand QRandomGenerator.
-
If you need boundaries then use
bounded()instead ofgenerate().
It will not change themin()/max()result but it returns the bounded result directly.BTW, mine
QRandomGenerator::max()returns 4294967295 andQRandomGenerator64::max()returns 18446744073709551615.
So if you are usingQRandomGenerator64which returns aquint64value and assign the result to anint, then it is normal to get a negative number . -
If you need boundaries then use
bounded()instead ofgenerate().
It will not change themin()/max()result but it returns the bounded result directly.BTW, mine
QRandomGenerator::max()returns 4294967295 andQRandomGenerator64::max()returns 18446744073709551615.
So if you are usingQRandomGenerator64which returns aquint64value and assign the result to anint, then it is normal to get a negative number . -
@Bonnie , thank you. I understand - in my system the maximum unsigned long long integer is two times less than the maximum from the generator.
@tsvigo
Not sure quite what you mean or if there is still a question?QRandomGeneratorhas overloads which returnquint32orquint64withgenerate[64]()andbounded(). If necessary pass your desired maximum value tobounded().The return values of
quint32orquint64are not "negative", they are unsigned/positive. What you do with that and when "written through the number" is a different matter.