A quick question

This is a discussion on A quick question within the C++ Programming forums, part of the General Programming Boards category; Is it possible to assign the value generated from srand() to a variable?? Cheers...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    59

    A quick question

    Is it possible to assign the value generated from srand()
    to a variable??


    Cheers

  2. #2
    fry
    fry is offline
    Registered User fry's Avatar
    Join Date
    Mar 2002
    Posts
    128
    yes.
    Code:
    srand();
    int x = rand();
    Or many variations of that, depending on your code...
    Last edited by fry; 10-03-2002 at 04:41 AM.
    IDE: Dev C++ 5
    Lib: Allegro
    OS: Windows 2000

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    All srand() does is seed the random numbers you later produce with rand()...it returns void, so you cant assign its return to anything.

    Might I suggest this

    <edit> Ahh...!.....I saw you change that fry ....Also, srand takes a parameter.....</edit>

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    59
    thanks guys,

    but what about if you have several srands() in your program
    and you want to assign them to different variables??

    sorry to be a pain.


    cheers

  5. #5
    fry
    fry is offline
    Registered User fry's Avatar
    Join Date
    Mar 2002
    Posts
    128
    You only need to srand() once, i believe.
    IDE: Dev C++ 5
    Lib: Allegro
    OS: Windows 2000

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    59
    What i ment was, i am going to generate several random numbers
    and i needed to assign them to indivdual variables.


    can anyone help please

    thanks in advance

  7. #7
    Registered User
    Join Date
    Oct 2002
    Posts
    59
    aha sorted it out now!!

    just goes to show if you play about abit with your code

    you can get it to work!!


    Thanks to the above people for your help........

  8. #8
    fry
    fry is offline
    Registered User fry's Avatar
    Join Date
    Mar 2002
    Posts
    128
    Playing around with your code is the most effective way to learn what you can and can't do
    Always try stuff yourself before asking others, you will learn a great deal more!
    IDE: Dev C++ 5
    Lib: Allegro
    OS: Windows 2000

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21