Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1996
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1996

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Matching random numbers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg4638] Re: Matching random numbers
  • From: browe at netcom.com (Bill Rowe)
  • Date: Thu, 22 Aug 1996 03:54:55 -0400
  • Organization: none apparent
  • Sender: owner-wri-mathgroup at wolfram.com

In article <4uphfg$6b5 at dragonfly.wolfram.com>, "A. Ortiz-Tapia"
<ao202 at cus.cam.ac.uk> wrote:

>I have written the following program:
>
>In[3]:=
> (count = 0 ;
>  Label[nextrandom];
>  pileup = pileup + 1;
>  x = Random[];
> y = Random[];
> a = Round[100*x]; 
> b = Round[100*y]; 
> If[a== b,Return[x], Goto[nextrandom]];
>  If[count == 5000, Break[]]; 
>Goto[nextrandom])
>
>The purpose of this program is to produce two inpendent random numbers;
>match this two numbers by "converting" them to integers, then if they
>are equal print either of them (I choosed x), *and* increment the value
>of a variable, such that at the end I can have 5000 "matched" random
>numbers. The program, so far, gives out *only one number*.

The exit condition for the loop occurs when a == b. The statement
Return[x] causes the loop to be exited and returns a single value, x.

To return the x,y pair, you could change the Return statement to Return[{x,y}].

BTW, this program seems to have some problems. It appears you intend for
the program to exit after 5000 tries. The variable count is set to 0 and
never incremented. So the If[count == 5000, Break[]]; statement the test
will always evaluate as false and the Break[] statement will never
execute.

The speed of the program would proabably benefit by using either the Do or
While constructs.

-- 
"Against supidity, the Gods themselves contend in vain"

==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Integration of Bessel functions
  • Next by Date: Re: 13 is not prime!
  • Previous by thread: Re: Matching random numbers
  • Next by thread: Compiled functions