comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@attbi.com>
Subject: Re: Problems with Ada.Real_Time on GNAT?
Date: Mon, 27 May 2002 02:42:57 GMT
Date: 2002-05-27T02:42:57+00:00	[thread overview]
Message-ID: <3CF19E8E.9090304@attbi.com> (raw)
In-Reply-To: 28d8936a.0205161133.3c9064b7@posting.google.com

file13 wrote:

> Hi guys.  There was a silly little contest on a web BBS where people
> were asked to write a program in any language (rules in the source). 
> I decided to represent for us Ada folks and produced this on GNAT 3.14
> on Windows 2000
> 
> http://www.qlippoth.com/shuffle.adb



Normally I would fault you on your approach.  Randomizing a list this 
way is biased.  This can easily be seen by the fact that if N=3, there 
are 3**3 = 27 possible random sequences, and 3! = 6 random permutations. 
  So some permutations must occur more often than others.  (In this 
case, the permutations 132, 213, and 231 will occur more often than 123, 
312, and 321.)  One million is a large enough sample that this won't be 
a problem.  (But notice that the bias is still there-- 1000000! does not 
evenly divide 1000000**1000000. ;-)

The way to avoid the problem for small arrays is to generate N random 
floats (or integers) do an index sort of that list, and use that as the 
result.  But at 1000000 values, float random variates over [0.0..1.0) 
don't have enough potential different values to avoid a significant 
number of collisions.  Using (32-bit) integer variates will help, but 
again the bias is probably not an issue for N > 100.  Just don't use the 
technique in this program to shuffle a deck of cards. ;-)

Incidently I did compare the two techniques in this case, and the 
sorting method was slower, but not significantly so.  (I used a 
quicksort, this is a case where a radix sort might be better.)




      parent reply	other threads:[~2002-05-27  2:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-16 19:33 Problems with Ada.Real_Time on GNAT? file13
2002-05-16 20:18 ` Florian Weimer
2002-05-16 20:53   ` David C. Hoos
2002-05-17  6:57     ` Florian Weimer
2002-05-17  9:57       ` Robert Dewar
2002-05-17 18:38         ` Florian Weimer
2002-05-18  2:49           ` Robert Dewar
2002-05-17 19:49         ` file13
2002-05-17  4:36 ` Per Sandbergs
2002-05-27  2:42 ` Robert I. Eachus [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox