0

i want to get a random value from the set of values like{1,2,5}

how can i do that

is that possible

i m not that familiar with using random function so plz xplain a bit how to use it if it can be used in this case

3
Contributors
7
Replies
9
Views
6 Years
Discussion Span
Last Post by kohoko
1

rand() will return a random number. If you want to restrict it to a set of numbers between 0 and N than use the mod % operator, such as int x = rand() % N;

0

hmm ohk.... so there is no possiblity to define a set of values

0

Well, if you have a set of values and you want to select one of them at random, then use rand() as I explained previously and use that value as the index into the array. The value of N in this case will be the amount of numbers in the array. In the example you posted replace N with 3 because the array contains 3 values.

0

thankQ for your valuable suggestion
:)
thanks a lot :)

-1

It is very difficult to get the random values in C language

Votes + Comments
Your links don't show up on Google, so stop posting crap
0

It is very difficult to get the random values in C language

Bullshit! How difficult is it to call rand() function?

Edited by Ancient Dragon: n/a

0

hey dragon i wasnt familiar wid random function ...n the idea u gav with that it is very easy to do the prog thanks a lot :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.