Unique random number sequence using qrand () and qsrand ()

I want to generate a unique sequence of random numbers in QT using QDateTime :: currentDateTime (). toTime_t () as a starting value, qrand () generates unique random numbers?

+3
source share
3 answers

No. qrandcan only generate as many unique numbers as fit into an integer, so - regardless of implementation - you cannot count on uniqueness.

Also, knowing that another seed creates another random integer will give you a level of predictability that actually makes it qrandno longer random.

: , , ; , :

alt text http://www.dilbert.com/dyn/str_strip/000000000/00000000/0000000/000000/00000/2000/300/2318/2318.strip.gif

+8

, , ( ) UUID. . QUuid. ( ):

createUuid(). UUID, createUuid(), . QUuid::Version QUuid::Random, QUuid::Variant QUuid::DCE. UUID . , UUID, createUuid(), . .

, UUID , , , , libuuid - .

+6

Qt Documentation, QRand - rand(), , / rand() .

I think you need to use a different terminology than "unique" random numbers (no pseudo random number generator will create a unique stream, since input X will always produce output Y). What is the real situation?

0
source

Source: https://habr.com/ru/post/1713878/


All Articles