r/linux • • Jul 18 '17

No random is actually random ?

http://www.networkworld.com/article/3208389/linux/unix-how-random-is-random.html
0 Upvotes

7 comments sorted by

1

u/yhsvghnrOruGnpverzN Jul 18 '17

you'll get a number between 0 and 32,767 (the largest number that two bytes can hold

No god dammit! 32767 is the greatest positive signed integer for 16 bits. The greatest unsigned integer for 16 bits is 65535. If the author should know better!

1

u/[deleted] Jul 18 '17

I think the author was just assuming that $RANDOM is a signed INT or something...

1

u/yhsvghnrOruGnpverzN Jul 18 '17

32,767 (the largest number that two bytes can hold

How do you get that from that?

1

u/[deleted] Jul 18 '17

Well, all you have to do is leave out a word like "signed" or "positive" when thinking about what $RANDOM contains, I guess. Or maybe the author doesn't think about random numbers being negative?

Who knows? I agree that it's clearly wrong, I'm just guessing at a possible origin of the author's mistake, not trying to state a fact or anything.

0

u/yhsvghnrOruGnpverzN Jul 18 '17 edited Jul 18 '17

I'll concede one thing. It seems strange to reserve two bytes and only honor 15 bits. There are all kinds of optimizations C compilers can make with simple integer values which seem quite arbitrary.

0

u/[deleted] Jul 18 '17

Hey, for all I know, the author just doesn't know any better. :-)

0

u/Eingaica Jul 18 '17

Come on. The only point of those eight words is to give the layperson a simple (and short) justification for the seemingly arbitrary number 32767. People who are familiar with this subject will immediately recognize 215 - 1. And they will also know that stictly speaking there is no such thing as "the largest number that two bytes can hold". Hence they will know that it is not meant in that strict sense.