i can generate random number between two numbers in c using this..
arc4random()%(high-low+1)+low;
then now my requirement is…i want to make a number rare….thats mean if
high=5,
low=1,
and rare=3,
than 3 will be appeared much rarely than 1,2,4 and 5…
Thanks
You can use tables to calculate your final roll, similar to how pen and paper RPGs do this same type of calculation:
Roll 1 D 21 (easily possibly w/ code).
The advantage to this option is you get a strong sense of the exact probabilities you are dealing with. You can get a feeling of exactly how rare or common each number is, and you get fine-grained control of how common each number is, in comparison to the other numbers.
You could also use fractions to generate the table. Use the Least Common Multiple to determine a common base. That base is the max random number size you will need. Then, put all the fractions in like terms. Use the resulting numerators to determine the size of the range for each number in the table.
With this automated solution, the input numbers are very easy to understand in relation to each other. E.g:
This would generate a table like so:
LCM = 20
Some more on LCM: http://en.wikipedia.org/wiki/Least_common_multiple