LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 10-04-2009, 09:23 PM   #1
ke121885
LQ Newbie
 
Registered: Oct 2009
Posts: 2

Rep: Reputation: 0
Question Rand_max


I am trying to print the value of RAND_MAX with this code:

Code:
#include <stdio.h>
#include <stdlib.h>

/*
*                       Main Function
*
*/

 main(void)
{

        printf("RAND_MAX = %d\n", RAND_MAX);
}
It is giving a number that is much larger than the 32767 that it is supposed to....any help?
 
Old 10-04-2009, 09:29 PM   #2
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 2,094

Rep: Reputation: 104Reputation: 104
from a 16 bit platform are we?
RAND_MAX in linux and windows has a 32 bit value (about 2 billion)
 
Old 10-04-2009, 09:34 PM   #3
ke121885
LQ Newbie
 
Registered: Oct 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Question next

Now I am supposed to use lrand48() and srand48() to see what generates....I am a little lost on this....sorry but thanks in advanced!
 
Old 10-05-2009, 12:39 AM   #4
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by ke121885 View Post
I am trying to print the value of RAND_MAX with this code:

Code:
#include <stdio.h>
#include <stdlib.h>

/*
*                       Main Function
*
*/

 main(void)
{

        printf("RAND_MAX = %d\n", RAND_MAX);
}
It is giving a number that is much larger than the 32767 that it is supposed to....any help?
Where are you getting the information about what RAND_MAX is "supposed to be"? It is what it is.

And what did the program print on your system? Didn't it occur to you that this would be useful for any meaningful reply?

32767 is 2^15-1. That is tiny by modern standards. It is virtually certain to not be the value of RAND_MAX, which is typically an unsigned value one less than the system's word length -- for a 32-bit machine that would be:

2^32-1 = 4294967295

Or, for a 64-bit machine:

2^64-1 = 18446744073709551615
 
Old 10-05-2009, 01:30 AM   #5
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 2,094

Rep: Reputation: 104Reputation: 104
on a 16 bit machine it is 32767
on a 32 bit machine it is 2147483647
on a 64 bit machine it is god knows what
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
srand(), rand(), RAND_MAX, or XXX weirdness nazdrowie Programming 2 03-07-2005 12:45 PM


All times are GMT -5. The time now is 12:10 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration