Results 1 to 4 of 4

Thread: Problem with random numbers. Rand() not working as expected.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2015
    Posts
    105
    Thanks
    50

    Default Re: Problem with random numbers. Rand() not working as expected.

    Thanks for your help d_stranz. I did what you said about bitwise operators.

    I figured out my problem, but i don't know exactly why and how to solve this. The problem is i instanced the File object in the MainWindow class definition. The problem is this object has to be alive all the time(until i close my program).

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,328
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with random numbers. Rand() not working as expected.

    So you can call srand() anywhere - it's just a C function. It doesn't have to be called anywhere in proximity to your use of rand() and has nothing to do with the scope or lifetime of your File object. If you are using a slot in MainWindow that responds to your button click, call it there and you'll re-seed the RNG on every click so should get a different series each time.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. random numbers and slots
    By Enoctaffie in forum Newbie
    Replies: 6
    Last Post: 14th April 2012, 07:54
  2. QDir not working as expected
    By BettaUseYoNikes in forum Qt Programming
    Replies: 2
    Last Post: 24th August 2011, 16:55
  3. Replies: 7
    Last Post: 22nd November 2010, 18:35
  4. Replies: 1
    Last Post: 7th April 2010, 16:26
  5. Qt large random numbers
    By timmu in forum Qt Programming
    Replies: 11
    Last Post: 31st August 2009, 08:22

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.