The new and updated "how do I use rand()" 
Author Message
 The new and updated "how do I use rand()"

Is this any better?

If I create a progrma with the rand() funtion.  How would I call it?
Plus, how would I tell it to only select a random number from 1-6?

The new and improved Zach.



Sat, 21 Apr 2001 03:00:00 GMT  
 The new and updated "how do I use rand()"

Quote:

> Is this any better?

Hi Zach Gorman,

Any better than what ? I seem to have missed what you are
referring to.

Quote:
> If I create a progrma with the rand() funtion.  How would I call it?
> Plus, how would I tell it to only select a random number from 1-6?

Hmmm, I just answered your other posting where you already have
included the source code. So I assume that this question is a
bit outdated. Generally I would have answered (for those who are
insterested in similar things): you can read the tips in the
comp.lang.c FAQ list, which generally is good reading material
*before* posting to a newsgroup:
   13.15:  I need a random number generator.
   13.16:  How can I get random integers in a certain range?
   13.17:  Each time I run my program, I get the same sequence of
numbers
           back from rand().

You can get the FAQ at http://www.eskimo.com/~scs/C-faq/top.html or
at ftp://rtfm.mit.edu/pub/usenet/comp.lang.c/C-FAQ-list and it gets
posted to this newsgroup and to news.answers regularly (at the
beginning of each month).

Stephan
(initiator of the campaign against grumpiness in c.l.c)



Sun, 22 Apr 2001 03:00:00 GMT  
 The new and updated "how do I use rand()"
:
: Actaully it was the first thing that I read, it did not help me
much....
[snip]
:: No, because you still have not read the C-FAQ
[snip]

well if you read sections 13.15 - 13.20
you should have deduced that you need to call
srand to set the seed (found in stdlib.h)
int x;
srand( (unsigned)time( NULL ) ); /* is nice don't forget time.h */
/*then  rand to get a random number*/
x = rand();
/* this number is somewhere in between 0 and RAND_MAX
 which is defined in stdlib.h and is usually 0x7fff */

if you now reread sections 13.15 - 13.20 you should be able to
discover how to get a random number within the range you want */

Ed



Mon, 23 Apr 2001 03:00:00 GMT  
 The new and updated "how do I use rand()"


Quote:
>Actaully it was the first thing that I read, it did not help me much....

Then you must have overlooked sections 13.15 to 13.20 (notably 13.16).
A simple text search on rand would have found these.

--
-----------------------------------------


-----------------------------------------



Mon, 23 Apr 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. MFC Container Classes using different "new" and "delete"

2. On using "using"

3. Closing shorter "updated" files

4. Q: Error message "Multiple rows updated"???

5. ODBC: "Multiple rows were updated" ERROR

6. CRecordset's Update seems "delayed"

7. UpdataData()"how to update"

8. "Update All Dependencies" missing

9. "Update All Dependencies" missing

10. Combo Box "Update"

11. (Updating "Add/Remove Programs" ListBox)

12. update "other" buttons during calculation

 

 
Powered by phpBB® Forum Software