Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Re: [mg4615] Matching random numbers
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Allan Hayes

Posts: 1,508
Registered: 12/6/04
Re: [mg4615] Matching random numbers
Posted: Aug 22, 1996 3:29 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"A. Ortiz-Tapia" <ao202@cus.cam.ac.uk>
[mg4615] Matching random numbers

I have written the following program:

(count = 0 ;
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[]];

The purpose of this program is to produce two inpendent random
numbers;match this two numbers by "converting" them to integers,
then if theyare equal print either of them (I choosed x), *and*
increment the valueof a variable, such that at the end I can have
5000 "matched" random
numbers. The program, so far, gives out *only one number*.

I would like to have some comments.

The following, written in a functional style more suited to Ma,
seems to do what you want. I have replaced 5000 with 10.

(mat= {};
While[Length[mat] <10,
If[Round[100#1]==Round[100#2], AppendTo[mat,#1 ]
]; mat)

{0.172357, 0.643095, 0.35482, 0.517124, 0.168319, 0.0228716,
0.183782, 0.406388, 0.0474315, 0.542734}

Allan Hayes

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum 1994-2015. All Rights Reserved.