porting to QRandomGenerator
-
I am porting some old code under qt 5.15.2.
qsrand(30);
qDebug() << "qrand" << qrand();
qDebug() << "qrand" << qrand();
qDebug() << "qrand" << qrand();this code always gives me the same result. With the same result I mean the same sequence. In the new code I have written:
QRandomGenerator generator;
generator.seed(30);qDebug() << "randomGenerator" << randGenerator.bounded(RAND_MAX);
qDebug() << "randomGenerator" << randGenerator.bounded(RAND_MAX);
qDebug() << "randomGenerator" << randGenerator.bounded(RAND_MAX);this too has always the same result but the values are different from the previous case. can i have the same result of the old qrand?
-
I am porting some old code under qt 5.15.2.
qsrand(30);
qDebug() << "qrand" << qrand();
qDebug() << "qrand" << qrand();
qDebug() << "qrand" << qrand();this code always gives me the same result. With the same result I mean the same sequence. In the new code I have written:
QRandomGenerator generator;
generator.seed(30);qDebug() << "randomGenerator" << randGenerator.bounded(RAND_MAX);
qDebug() << "randomGenerator" << randGenerator.bounded(RAND_MAX);
qDebug() << "randomGenerator" << randGenerator.bounded(RAND_MAX);this too has always the same result but the values are different from the previous case. can i have the same result of the old qrand?
@Massimiliano75 said in porting to QRandomGenerator:
can i have the same result of the old qrand?
I have no evidence for my answer, but I am interested in anything to do with random & pseudo-random numbers.
I would very much doubt that you can use the same seed, or even any other seed, to generate the same sequence as it used to be. I would imagine these two use different pseudo-generator algorithms, and hence won't produce the same sequences as each other. Seed or not.
I guess this could be a problem when upgrading for testing (with existing result sets), but haven't seen a comment about this.
Unless someone who knows the changed code tells you otherwise... :)
-
I am porting some old code under qt 5.15.2.
qsrand(30);
qDebug() << "qrand" << qrand();
qDebug() << "qrand" << qrand();
qDebug() << "qrand" << qrand();this code always gives me the same result. With the same result I mean the same sequence. In the new code I have written:
QRandomGenerator generator;
generator.seed(30);qDebug() << "randomGenerator" << randGenerator.bounded(RAND_MAX);
qDebug() << "randomGenerator" << randGenerator.bounded(RAND_MAX);
qDebug() << "randomGenerator" << randGenerator.bounded(RAND_MAX);this too has always the same result but the values are different from the previous case. can i have the same result of the old qrand?
@Massimiliano75 said in porting to QRandomGenerator:
can i have the same result of the old qrand?
You really should understand what 'random' means...