LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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
  Search this Thread
Old 10-04-2009, 10: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, 10:29 PM   #2
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,330

Rep: Reputation: 227Reputation: 227Reputation: 227
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, 10: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, 01:39 AM   #4
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
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, 02:30 AM   #5
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,330

Rep: Reputation: 227Reputation: 227Reputation: 227
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



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


All times are GMT -5. The time now is 06:39 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration