×
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

Random Number Generator

Random Number Generator

Random Number Generator

(OP)
I need some code help writing a random number generator. I
have never tried one before.

Using turbo C++
Thanks

RE: Random Number Generator

Do you want to write your own code or use the function random(int num) that comes with borland C++?
random(num) returns a random number between 0 and (num - 1).
randomize() initializes the random number generator with a random value. ;)




RE: Random Number Generator

(OP)
zBuilder,
I want to use the random(int num) function, but I am not familiar with how to use it. I kinda know what it does, and I know that I have to use stdlib.h, but I don't really know how to declare it.

CR

RE: Random Number Generator

You don't have to declare the random(int num) function, it is already declared in stdlib.h
Below is some code to help you pick your lotto #'s
(Note: it's not bullet proof because it doesn't check to see if the same # is picked twice, but it is simple and should give you the right idea about using the random function.)

#include <stdio.h>
#include <stdlib.h>

void main()
{
int x, YourNumber;

randomize(); //initialize the random # generator
printf ("Your 649 numbers are:\n\n");
for ( x = 1; x < 7; x++) // count out 6 random #'s
{
YourNumber = random(48) + 1; //Get a # between 1 & 49
printf( "%d: %d\n", x, YourNumber );
}
}

RE: Random Number Generator

I am only a student, but the program that I am working on now uses rand(). It is a program to help elementary students with their math. For difficulty level 1 it generates two numbers 0-9 to add, subtract, etc... For level 2, it generates two numbers 0-99. Here is the if statement that I am using to do this. rand()will generate
random numbers from 0-32000. I hope that this helps!!

if (difficulty == 1)
{
x = rand()%10;
y = rand()%10;
}
else
{
x = rand()%100;
y = rand()%100;
}

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