www.delorie.com/archives/browse.cgi | search |
X-Sender: | dlanor AT mail DOT dds DOT nl |
Message-Id: | <l03130304b364ec5e3186@[145.98.116.109]> |
In-Reply-To: | <7hmakj$t6h$1@cubacola.tninet.se> |
Mime-Version: | 1.0 |
Date: | Sun, 16 May 1999 23:52:20 +0200 |
To: | djgpp AT delorie DOT com |
From: | Dlanor Blytkerchan <dlanor AT dds DOT nl> |
Subject: | Re: ** Random error ** |
Reply-To: | djgpp AT delorie DOT com |
X-Mailing-List: | djgpp AT delorie DOT com |
X-Unsubscribes-To: | listserv AT delorie DOT com |
>Can somebody tell how I do to set the variable "int i" to a random number >from 1 to x? Try this macro: #define rnd(x,y) ((random()/RAND_MAX)*(y-x) + x); include stdlib and it should work like this int my_random_number = (int)rnd(1, my_top_number); Greetz! Dlanor NB: sometimes, using rand() is recommended over using random(). Why is not entirly clear, look it up in libc.
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |