Thread: rand () a little confusion

  1. #1
    Registered User Led Zeppelin's Avatar
    Join Date
    Mar 2002
    Posts
    17

    rand () a little confusion

    Before anyone hazes me for not checking the FAQ I did and didnt see anything related to the question.

    2 quick questions about rand()


    is,
    rand () % 10 + 1 the same thing as rand() % 11


    and can you use hex numbers. ex:
    rand () % 2 + 1f



    thanks

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >rand () % 10 + 1 the same thing as rand() % 11
    No, % has a higher precedence than +, so you obtain your random number from 10, then add one to the result. The second simply uses 11 to obtain the random number and the result from that is used as is and not modified.

    >and can you use hex numbers.
    Yes

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User Led Zeppelin's Avatar
    Join Date
    Mar 2002
    Posts
    17

    Prelude, thanks for the help

    Thank you

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Anytime

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Terrible confusion with time variables
    By LowlyIntern in forum C++ Programming
    Replies: 12
    Last Post: 08-01-2008, 07:23 AM
  2. C++ Classes: Use, Misuse...Confusion.
    By Snorpy_Py in forum C++ Programming
    Replies: 4
    Last Post: 10-23-2006, 01:46 AM
  3. for loop confusion
    By Enges in forum C++ Programming
    Replies: 6
    Last Post: 04-26-2006, 08:21 AM
  4. Server-net newbie confusion
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 04-28-2005, 02:08 AM
  5. confusion with increment and decrement operators
    By cBegginer in forum C Programming
    Replies: 6
    Last Post: 03-19-2005, 03:45 PM