×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Need help developing random function

Need help developing random function

Need help developing random function

(OP)
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

RE: Need help developing random function

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

hnd
hasso55@yahoo.com

RE: Need help developing random function

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

RE: Need help developing random function

cyprus106
between 0 and 9 :)

John Fill


ivfmd@mail.md

RE: Need help developing random function

o yeah, sorry.

Cyprus

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close