On Sun, 15 Jun 2014, montgrimpulo wrote: > this is a placeholder of the task which I am trying to solve in Ada. > As you may know in German Lotto there are 49 numbers 1..49 > from which you have to select 6 numbers to place a bet. > > First Round: > By defining a subtype valid for positive numbers from 1 .. 49, > the use of Ada.Discrete_Random, and the definition of an appropriate Generator > you may get a random number in the range of 1 .. 49. Call that number R_1. > Second Round: > Here does my problem start. Now I have a set of numbers where > one number - which was randomly selected in the first round - > is missing. How do I use the random function to select another > random number out of the rest ? There are a couple of different solutions. First Solution (in pseudo-code, not in Ada): repeat choose a random R_2 between 1 and 49 until R_2 /= R_1. Third round: Choose a random R_3 between 1 and 49 until R_3 /= R_1 and R_3 /= R_2. ect. Second Solution: choose a random R_2 between 1 and 48 If R_2=R_1 then R_1 := 49 choose a random R_3 between 1 and 47 If R_3=R_1 then R_3 := 48 elsif R_3=R_2 then R_3 := 49 ect. Now, for the second solution, you need random numbers from different intervals. In principle, you can (2a) instantiate a new generator from Ada.Numerics.Discrete_Random for each of the R_i. The alternative is to (2n) instantiate a single random generator (I've forgotten the package name, but it is not A.N.Discrete_Random), which just generates a Float F_Rand between 0 and 1. Then set R_I := Truncate(1 + F_Rand * (50-I)). > A workaround would be > to test in each round, if that number has already been selected. > However, the probability would not be the same as with a reduced > set as the selection would be always from the full set. That sounds like my first solution. If you repeat the random choice until you R_i is different from all the R_(i-1), ..., R_1, the probability is exactly the probability you expect. (Well, assuming the random generator is good.) ------ I love the taste of Cryptanalysis in the morning! ------ --Stefan.Lucks (at) uni-weimar.de, Bauhaus-Universität Weimar, Germany--