0% found this document useful (0 votes)
7 views

C-Programming PPT L15

C programming

Uploaded by

cbseadvisor1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

C-Programming PPT L15

C programming

Uploaded by

cbseadvisor1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

C Programming

MTL505
Lecture-15

Random number
Randomness and Random numbers
• A number of natural phenomenon are random in
nature
• Random numbers are very useful to create
simulation data, which can mimic real world or
experimental data. Such data is very useful for
development and validation of
methods/algorithms
• Real world data is always corrupted with noise of
certain amount (i.e. 5%, 10% of peak signal).
• Such noise can be mimicked using the concept of
random numbers
Random numbers or Pseudo Random Numbers
• A random number is a number chosen as if by chance from
some specified distribution such that selection of a large set
of these numbers reproduces the underlying distribution.

• Almost always, such numbers are also required to be


independent, so that there are no correlations between
successive numbers.

• Computer-generated random numbers are sometimes called


pseudorandom numbers, while the term "random" is
reserved for the output of unpredictable physical processes.

• By default, the word "random" usually means "random with


a uniform distribution." Other distributions are of course
possible.
Source: http://mathworld.wolfram.com/RandomNumber.html
Random numbers,
Pseudo Random Numbers
srand()
• The srand() function sets the starting point for producing a
series of pseudo-random integers.

• If srand() is not called, the rand() seed is set as if srand(1)


were called at program start.

• Any other value for seed sets the generator to a different


starting point.

• srand() sets the seed which is used by rand to generate


“random” numbers. If you don’t call srand before your first
call to rand, it’s as if you had called srand(1) to set the seed
to one.
In short, srand() — Set Seed for rand() Function.
Range of rand ()
• rand() function return integer value in the range of 0 to
RAND_MAX

• RAND_MAX depends upon operating system and can have


different range

• The constant RAND_MAX is defined in standard library


(stdlib).

• rand() provide random numbers with uniform distribution


Scaling or changing range of values
• Let data be in [m1, M1] range and we are
interested to convert it into [m2 M2] range

• Let x1 belongs to [m1 M1] and we want equivalent


value x2 in [m1 M2]
– (x1-m1)/(M1-m1) = (x2-m2)/(M2-m2)

• Therefore:
– x2 = m2 + (x1-m1)/(M1-m1)*(M2-m2)

You might also like