4

I realize in some programming languages, random number generators generate a default value of 0 to 32767 (for example, in php, rand(); will return a float between 0 and 32767). What is the significance of such a random number? (As it is not a power of two or anything special like that.)

TylerH
  • 20,799
  • 66
  • 75
  • 101
Anson Savage
  • 283
  • 3
  • 5
  • 12
  • 2
    Maybe read this: http://stackoverflow.com/questions/18558271/why-the-range-of-int-is-32768-to-32767 – ficuscr Jun 04 '15 at 20:12

3 Answers3

30

It is 2^15-1, so the maximum value of a 16-bit signed integer.

TylerH
  • 20,799
  • 66
  • 75
  • 101
FPK
  • 2,008
  • 13
  • 19
  • 2
    Yeah, this is a good answer and 7 years later as a CS Major in college, I understand what it means! I was pretty clueless back in high school :)) Thanks! – Anson Savage Sep 06 '22 at 01:06
3

I guess, On 16-bit implementations (still common when the C89 standard was written) that was the largest signed integer.

XOR-Manik
  • 493
  • 1
  • 4
  • 19
0

32767 + 1 is a power of 2 Binary representation of numbers uses powers of 2. So, in an 4-bit structure, 0101 is 2^0 x 1, 2^1 x 0, 2^2 x 1, and 2^3 x 0 which is 5.

The MSB is used for sign and unsigned integers.

Kirk Powell
  • 908
  • 9
  • 14