# Thread: Seed parameter thro srand function

1. ## Seed parameter thro srand function

hai

I am having some understanding problem when i give like

srand(5);

then when i give

a = int rand();

only randam numbers got generated as 0<a<1

then what is the meaning for giving seed parameter thro srand function.

can anyone pls explain me...

2. ## Re: Seed parameter thro srand function

Hi Surya,

srand(x) function uses the argument 'x' to start a new sequence of random numbers to be returned when you call rand(). If you use the same seed 'x' in another srand function, it generates the same sequence of random numbers, and if you change the seed, it will generate different set of random numbers.

Praveen

3. ## Re: Seed parameter thro srand function

rand() returns a random value between 0 and 0.9999....

int(x) returns the integer portion of x, stripping off everything after the decimal point.

Therefore, int(rand()) will always return 0.

If you want a random integer between 1 and 5, then you can use:

myNumber = int(rand() * 5) + 1;

4. ## Re: Seed parameter thro srand function

Thank u very much for ur kind explanations. I will be very help full for me.

Thanks and regards

N.Suresh

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.