Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. porting to QRandomGenerator
Qt 6.11 is out! See what's new in the release blog

porting to QRandomGenerator

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 527 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Massimiliano75
    wrote on last edited by Massimiliano75
    #1

    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?

    JonBJ Christian EhrlicherC 2 Replies Last reply
    0
    • M Massimiliano75

      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?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @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... :)

      1 Reply Last reply
      4
      • M Massimiliano75

        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?

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Massimiliano75 said in porting to QRandomGenerator:

        can i have the same result of the old qrand?

        You really should understand what 'random' means...

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved