Results 1 to 8 of 8

Thread: Two problems with the function qrand()

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Two problems with the function qrand()

    Lesiok is correct; calling qsrand() more than once is not something you need to do.

    As for repeating numbers: that's going to depend partly on what range you give your functions. If you're generating numbers within a narrow range, repeats are going to occur very frequently.

    Although there are many, many different tests for randomness, the simplest one would be to check the frequency of each number; ideally, they should all occur the same number of times over a large run. You can also concoct series metrics by determining the probability that two, three or more numbers would occur after one another, and compare that to the output of your function.

    My guess is that qrand is doing what it's supposed to do. Nearly all of the problems I've run across involving RNGs can be traced to misunderstandings on the part of those using the routines.

    Note, too, that ALL numerical RNGs repeat the same sequence of numbers over and over and over again; algorithms are chosen that produce series with extremely long periods, but it is the nature of deterministic calculation that no such procedure can ever generate truly random numbers. It can only produce a stream of numbers that displays attributes very close to what would be expected from a truly random process.

  2. The following user says thank you to SixDegrees for this useful post:

    Trader (5th November 2010)

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

    Wink Re: Two problems with the function qrand()

    Lesiok && SixDegrees

    It worked perfectly.

    Thank you!!!

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Two problems with the function qrand()

    If one is using a unix system, a good source for random numbers is /dev/random. It has a limited output rate but it's a good way to get a unique random sequence by initializing the seed of the random number generator with data from /dev/random. This allows to get unique sequences on different machines (which is not the case with seed related to the current time as in the example above).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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.