rand() function?

This is a discussion on rand() function? within the C++ Programming forums, part of the General Programming Boards category; I'm a rookie when it comes to programming but I have this program I've been working on that uses the ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    60

    rand() function?

    I'm a rookie when it comes to programming but I have this program I've been working on that uses the "rand ()" function. I understand that this function gives a random integer value between 0 and 32767 but what is the significance of this value? Why 32767? Thanks for any help in advance.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,788
    Well, 32767 is ((2 raised to the 16th power) divided by 2) minus 1... which is the maximum positive signed integer (16-bit signed int) value possible. Actually it returns a value from 0 to RAND_MAX, whatever RAND_MAX happens to be on your compiler. On my compiler it is defined as 0x7FFF which is indeed 32767.
    Last edited by hk_mp5kpdw; 03-08-2005 at 06:59 PM.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    In binary, it's 15 bits, a range of (2^15) of different values.

Popular pages Recent additions subscribe to a feed

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