Skip to content

aida72/RandomNumberGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PROGRAM DESCRIPTION:

The program is written in c and since c support for different methods such as random number generation is expanded in different libraries we first include libraries for support of time(), rand(), srand(), rand() methods
as these are the methods used to generate a random number with a certain accuracy as randomness is concerned.
rand( ) returns a random positive integer in the range from 0 to 32,767.
This function can be thought of as rolling a die with 32,767 faces.
The numbers are generated by a mathematical algorithm which when given a starting number (called the "seed"),
always generates the same sequence of numbers. Since the same sequence is generated each time the seed remains
the same, the rand( ) function generates a pseudo-random sequence. To prevent the same sequence from being \ generated each time,we use srand(x) to change the seed value.
Using srand(time(NULL)); makes use of the computer's internal clock to control the choice of the seed.\ Since time is continually changing, the seed is forever changing. In order to produce random integer numbers within a specified range, you need to manipulate the rand( ) function. The formula is:

int number = a + rand( ) % n;

a = the first number in range
n = the number of terms in range
(range computed by largest value - smallest value + 1)
In our case we have : current = rand() % 10 + 1; for numbers from 1 to 10.
current holds the current random value generated for each loop of while.
This value is saved on array used. This array serves to prevent duplicates since we could have cases
with duplicate values generated and the request specifies that we will have each value once but in random order.
The for loop checks array used if any element in it has the same value of current value generated.
If such is the case, another int value continue_next is assigned to 1, which will be used at the condition:
if(continue_next == 0). So by checking this variable we ensure there are no duplicates when displaying
the numbers generated with printf and also this method is called exactly 10 times by controlling when variable
i is incremented.


HOW TO RUN THE PROGRAM ON LINUX AND MAC OS:

LINUX

First save the program as program.c.

Then open a terminal and type:

gcc program.c -o program.c

Then you can run it with:

./program

MAC OS

First save the program as program.c.

Now you need the compiler, so you need to go to App Store and install Xcode which is Apple's compiler and development tools.

Then you need to install the command-line tools in Terminal.

Now we install the command-line tools like this:

xcode-selectinstall


Then you can compile your code with by simply running clang like this:

clang program.c -o program

Then you can run it with:

./program

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages