Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help developing random function

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I need help concerning a rather simple problem. I need to develop a function that creates a random integer between 0 and a maximum integer that is supplied as a parameter. However, I don't know a good algorithm to use to develop random numbers, and need help. Any help is appreciated. Thanks.

Duprasi
 
Do you look for real random numbers or pseudo-random numbers.

In the first case you should use random outside events to create random numbers (Time between key clicks, Microphone and noise Level...)

In the other case you could use the build in random generator.

A useful algorithm may be:

double n,f;
n= init value; between 0 and 1

// begin of sequence
f=n+M_PI;
f=f*f*f*f*f;

//newvalue
n=f-int(f);
// end of sequence
repeat this sequence as often you want [sig]<p>hnd<br><a href=mailto:hasso55@yahoo.com>hasso55@yahoo.com</a><br><a href= > </a><br> [/sig]
 
try this:

srand((unsigned) time (NULL));
int x=rand()% 10

this will give you a random number between 0 and 10 not including 10.

you can probably take it from there, but if you cant, mail me, and ill get you more Cyprus
 
cyprus106
between 0 and 9 :) John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top