Results 1 to 8 of 8

Thread: Two problems with the function qrand()

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    May 2010
    Posts
    21
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Two problems with the function qrand()

    tbscope:

    this: 10 10 10 10 11 15 21 21 21 21 21


    Added after 28 minutes:


    high_flyer: "you need a new seed for each new random set. use void qsrand ( uint seed ). If you have read qrand() doc, you would have known it."

    I'm using qsrand. See the function: randInt2

    I found this in other forums that spoke the same problem.



    "What you see is the effect of pseudo-randomness. You seed it with the time once, and it generates a sequence of numbers. Since you are pulling a series of random numbers very quickly after each other, you are re-seeding the randomizer with the same number until the next millisecond. And while a millisecond seems like a short time, consider the amount of calculations you're doing in that time."



    "If you make the call fast enough the value of QTime::currentTime().msec() will not change, and you're basically re-seeding qsrand with the same seed, causing the next random number generated to be the same as the prior one."



    I think I need something faster than milliseconds, maybe the CPU clock cycles.

    Is there any solution to this problem?
    Last edited by Trader; 5th November 2010 at 13:49.

Similar Threads

  1. Replies: 0
    Last Post: 10th March 2010, 08:13
  2. Replies: 22
    Last Post: 8th October 2008, 13:54
  3. Problems passing an array of pointers to objects to a function
    By Valheru in forum General Programming
    Replies: 16
    Last Post: 30th June 2008, 00:11
  4. const function parameter problems
    By stevey in forum General Programming
    Replies: 3
    Last Post: 18th December 2006, 22:22
  5. Problems calling C function in C++/Qt class
    By Rayven in forum General Programming
    Replies: 2
    Last Post: 2nd June 2006, 21:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.