Do you want to write your own code or use the function random(int num) that comes with borland C++? <br>
random(num) returns a random number between 0 and (num - 1). <br>
randomize() initializes the random number generator with a random value. <br>
<br>
<br>
<br>
<br>
zBuilder,<br>
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.<br>
<br>
CR
You don't have to declare the random(int num) function, it is already declared in stdlib.h<br>
Below is some code to help you pick your lotto #'s<br>
(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.)<br>
<br>
#include <stdio.h><br>
#include <stdlib.h><br>
<br>
void main()<br>
{<br>
int x, YourNumber;<br>
<br>
randomize(); //initialize the random # generator<br>
printf ("Your 649 numbers are:\n\n");<br>
for ( x = 1; x < 7; x++) // count out 6 random #'s<br>
{<br>
YourNumber = random(48) + 1; //Get a # between 1 & 49<br>
printf( "%d: %d\n", x, YourNumber );<br>
}<br>
}
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<br>
random numbers from 0-32000. I hope that this helps!!<br>
<br>
if (difficulty == 1)<br>
{<br>
x = rand()%10;<br>
y = rand()%10;<br>
}<br>
else<br>
{<br>
x = rand()%100;<br>
y = rand()%100;<br>
}<br>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.