comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: Pseudo Random coding problem
Date: Wed, 08 Jan 2003 01:55:07 GMT
Date: 2003-01-08T01:55:07+00:00	[thread overview]
Message-ID: <%xLS9.675327$NH2.47318@sccrnsc01> (raw)
In-Reply-To: 3e1b633f.3280604@news.demon.co.uk

> sometimes sees the value 20 and on other occasions doesn't.

You are generating 30 random integer from 1 ..  50 (15 from the
"Ada.Integer_Text_IO.Put" and another 15 from the
"if Random_50.Random(Gen => G) = 20 then").  The probability that
none of those is a 20 is (49/50)**30 = 0.55   If the 20 should come
up on the "Ada.Integer_Text_IO.Put" you will see it printed
out.  Since those are half of the 30 calls, you ought to see "20"
printed about 0.27 of the time.  If the 20 comes up on the
"if" statement instead, you won't see a 20 at all, but will instead
see "Random Number is equal to Twenty".  That also should happen
on about 27% of the runs.  Running your program 100 times, a quarter
second apart (to let the random generator start differently), I
see 26 of the runs output "Random Number is equal to Twenty" at
least once.  Sounds just about right.



  reply	other threads:[~2003-01-08  1:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-07 23:47 Pseudo Random coding problem Brian A Crawford
2003-01-08  1:55 ` tmoran [this message]
2003-01-08 10:57   ` Brian A Crawford
2003-01-08 13:45     ` David C. Hoos
2003-01-08  4:08 ` Andy Starritt
2003-01-08 20:56 ` Stephen Leake
  -- strict thread matches above, loose matches on Subject: below --
2003-01-08 13:45 David C. Hoos
replies disabled

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