From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Lotto simulation Date: Sun, 15 Jun 2014 21:43:25 +0100 Organization: A noiseless patient Spider Message-ID: References: <77cc4476-8c57-481b-afb9-8f53f8b16e37@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="a4a86ddfabe7a860897511d47e5acc83"; logging-data="16438"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+sDf13jDtvXXngS8mYmw+EBm2SAQVeaIY=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) Cancel-Lock: sha1:4n4x6c/Ti3wkOpJlS2dDDeWKq98= sha1:AalDFLhc9Xyz8luuLO+SBKKFkyc= Xref: news.eternal-september.org comp.lang.ada:20330 Date: 2014-06-15T21:43:25+01:00 List-Id: Dirk Heinrichs writes: > 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. >> >> 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 ? >> >> Any ideas to answer that question ? > > Let's look at how it works in reality: A random ball is selected out of a > set of 49 balls, mixed randomly before the pick, resulting in a new set of > 48 balls, etc. > > So you'd need to start with a sorted array of integers 1 to 49, mix it > randomly and then pick a random index out of 1 to 49. The number at that > index is then removed from the array. Why mix it? > You'd then create a new array of 48 integers filled with the numbers at 1 to > picked-1 plus picked+1 to 49 of the former array, mix that array again and > pick a random index out of 1 to 48. Again remove the number at that index. But Ada.Numerics.Discrete_Random picks a random value of the Result_Subtype it was instantiated with. So if you want to pick a number in 1 .. 48 you have to create a new instantiation. And the RNG is going to start off in some state, unrelated to the present state of the RNG for 1 .. 49. How are you going to be sure that it's not going to return 1 every time?