rand () a little confusion

This is a discussion on rand () a little confusion within the C Programming forums, part of the General Programming Boards category; Before anyone hazes me for not checking the FAQ I did and didnt see anything related to the question. 2 ...

  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,796
    >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,796
    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, 02:45 PM

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