This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
gcc newbie: rand()
- To: help-gcc at gnu dot org
- Subject: gcc newbie: rand()
- From: Joachim Bauernberger <nuklear at singnet dot com dot sg>
- Date: Fri, 10 Dec 1999 20:03:06 +0800
- Newsgroups: gnu.gcc.help
- Organization: Singapore Telecommunications Ltd
- Xref: wodc7nx0 gnu.gcc.help:2148
/* hi there!
*
* can anybody tell my why the following code compiled with:............
* gcc -g -D_GNU_SOURCE filename.c -o outputfile
*
* ....generates all sort of strange numbers but when compiled under
borland gives me the desired * random numbers between 1 and 6 ??? how
do i do it to get the numbers between 1 and 6.
* this example is from a book about C so it can't be that wrong, can
it?
*/
#include <stdlib.h>
#include <stdio.h>
#define SEED 12345
main()
{
float x;
int n;
srand(SEED);
x = rand() /32768.0;
n = 1 + (int) (6 * x);
printf("x = %d", n);
}
/*Thank's
Joachim!
*/