# Thread: Doubts regarding random numbers generation

1. ## Doubts regarding random numbers generation

At first my new year wishes to all members.

My doubts are

1. How can i generate 10 random numbers from 1 to 10, But here the condition is the generated random numbers should be odds only and not evens or vice versa.

2. The srand() function uses a different seed value on every run, causing a different set of random values every run. According to this, the srand() function gets one different vlaue for each run. Can we can't get more than one values for srand() function for each run of program.

Thanks

2. 1. use rand() % 10 + 1 if it's even (result % 2 == 0) then add 1 to make it odd be careful with 10 though -- 10 is even so you can ignore that anyway and generate from 1 to 9.
2. What?!? You seed the random number generator with srand()

3. Originally Posted by girish1026
My doubts are
im confused by your use of "doubts". do you mean something like "constraint" or "restriction"/"requirement"?

1. How can i generate 10 random numbers from 1 to 10, But here the condition is the generated random numbers should be odds only and not evens or vice versa.
so you want even numbers from 1-10? simply generate numbers from 1-5 and multiply each by 2 (resulting in 2,4,6,8,10).

2. The srand() function uses a different seed value on every run, causing a different set of random values every run.
otherwise it wouldnt be very random would it?!
According to this, the srand() function gets one different vlaue for each run. Can we can't get more than one values for srand() function for each run of program.
your wording is confusing. what exactly are you asking? if you dont provide a seed, you should get the same sequence if thats what your looking for. if your wanting to provide two seeds there isnt really a point, the first one should make it random enough. most often people will use the current time as the seed.

so you want even numbers from 1-10? simply generate numbers from 1-5 and multiply each by 2 (resulting in 2,4,6,8,10).
And subtract 1 to get the odds

5. Originally Posted by girish1026
My doubts are
Just so you know, you've been taught wrong. The word you should have used is "question", not "doubt", and a question must end in a question mark (a "?").
You can be pretty sure that the word "doubt" is basically never the right word to use if English is your second language.

6. Originally Posted by iMalc
You can be pretty sure that the word "doubt" is basically never the right word to use if English is your second language.
I sort of doubt that

Just to clarify for girish1026, however, the word "doubt" is a verb for "being uncertain", but it is always used in contexts where there is some level of distrust. The word "question" is used to raise a concern for discussion, when seeking a reply or explanation, in a more neutral manner.

7. I have a doubt regarding the use of doubt, is it okay?

Oh snap.

8. <LOL>

Thanks, Zacks7!

9. Originally Posted by grumpy
And subtract 1 to get the odds
hmm i dont know if you are serious or not! but if he/she was asking for even random numbers from 1-10, using random numbers from 1-5 and multiplying will give range of 2,4,6,8,10. im not sure what you mean by subtract 1 for the odds? unless of course I am misunderstanding the question! oh well