delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/07/15:17:40

Date: Tue, 7 Oct 1997 14:18:47 -0500 (CDT)
From: Andrew Deren <aderen AT eecs DOT uic DOT edu>
To: Robert Debeljakovic <rdebelj AT wt DOT com DOT au>
cc: djgpp AT delorie DOT com
Subject: Re: [Q] Whats wrong here...
In-Reply-To: <61canb$kjf$1@kurica.wt.com.au>
Message-ID: <Pine.SUN.3.95.971007141817.12383B-100000@ernie.eecs.uic.edu>
MIME-Version: 1.0

On Tue, 7 Oct 1997, Robert Debeljakovic wrote:

> Ok, look at the following code....
> ----------------------------------------------------
> #include <stdio.h>
> #include <stdlib.h>
> #include <conio.h>
> 
> void Random(int MaxValue)
> {
> int x;
> 
> x= -1;
> if((x < 0)||(x > MaxValue))
>   x=rand();

To get a random number in range 0 to 100 use:
x = rand()%100;


> printf("[%d]\n",x);
> }
> 
> void main(void)
> {
> int i;
> printf("Press return to get 10 numbers between 0-100\n");
> getch();
> for(i=0;i<10;i++)
>   Random(100);
> printf("<press any key to continue>\n");
> getch();
> }
> ------------------------------------------------------------------
> 
> Why does it keep giving me HUGE numbers?
> Please help this BLIND man see!!!
> 
> Cheers,
> Robert Debeljakovic.
> West Oz
> 


                        ,,,
                       (0 0)
   +-------------oOO----(_)-------------------+
   |                Andrew Deren              |  
   |             aderen AT eecs DOT uic DOT edu          |
   | www.eecs.uic.edu/~aderen/ader/main.html  |
   +-------------------------oOO--------------+
                       || ||
                      ooO Ooo
 


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019