Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #14110

Re: Testing a random integer generator

From Ray Koopman <koopman@sfu.ca>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Testing a random integer generator
Date 2013-04-09 08:04 +0000
Message-ID <kk0i33$2tl$1@smc.vnet.net> (permalink)
References <kjqjln$37o$1@smc.vnet.net>
Organization Time-Warner Telecom

Show all headers | View raw


On Apr 6, 6:55 pm, Clif McInnis <c_mcin...@hotmail.com> wrote:
> I am trying to test the random integer generator in a program to make sure
> that it gives the type of output that I am looking for. I expect it to generate (p<>q)<10 slightly less than 1/8 of the time and (p=q)<10 slightly more than 1/8 of the time, 9<(p<>q)<20 slightly less than 3/8 of the time, and 9<(p=q)<20 slightly more than 3/8 of the time. Regardless of my expectations I would like to see how the numbers actually come out, and to that end was attempting to test the test the code, but I can not get it to generate (print) any numbers. I am sure that I have made an error somewhere in the code, but I can not find it and am not getting any error messages. Thank you for any and all help.
>
> Clif McInnis
>
> Initialization :> ({x = 0, p = 0, q = 0})
> While[x < 100, {
>   Clear[p, q],
>   q = RandomInteger[{1, 4}], If[q < 4,
>    {p = RandomInteger[{10, 20}],
>     q = RandomInteger[],
>     If[q == 1, q = p, q = RandomInteger[{10, 20}]]}, {p = RandomInteger[{1, 9}],
>     q = RandomInteger[],
>     If[q == 1, q = p, q = RandomInteger[{1, 9}]]}], Print[p],
>   Print[q]}; x++]

randompair[range_] := {#, If[RandomInteger[] == 0,
  #, RandomInteger[range]]} & @ RandomInteger[range]

Table[randompair@If[RandomInteger[3] == 0, {1, 9}, {10, 20}], {100}]

{{14, 14}, {14, 15}, {12, 12}, {5, 1}, {5, 5}, {17, 17}, {18, 11},
 {13, 13}, {20, 11}, {15, 15}, {11, 19}, {6, 6}, {14, 20}, {5, 9},
 {14, 12}, {7, 7}, {15, 15}, {13, 17}, {13, 17}, {10, 10}, {20, 17},
 {10, 17}, {17, 17}, {17, 17}, {9, 9}, {8, 6}, {15, 13}, {18, 18},
 {3, 3}, {18, 12}, {13, 19}, {18, 18}, {8, 3}, {5, 6}, {5, 5},
 {13, 16}, {20, 20}, {18, 18}, {20, 20}, {14, 14}, {10, 16},
 {17, 12}, {17, 18}, {18, 20}, {18, 16}, {14, 14}, {20, 14},
 {19, 19}, {2, 2}, {20, 17}, {10, 15}, {17, 17}, {5, 5}, {7, 3},
 {4, 4}, {16, 16}, {16, 18}, {3, 5}, {7, 7}, {20, 20}, {13, 13},
 {18, 16}, {13, 13}, {7, 7}, {11, 13}, {17, 17}, {8, 8}, {17, 17},
 {19, 17}, {19, 14}, {19, 14}, {19, 19}, {19, 19}, {19, 19},
 {14, 14}, {6, 8}, {8, 8}, {1, 1}, {15, 17}, {15, 15}, {18, 18},
 {20, 17}, {10, 10}, {16, 15}, {10, 13}, {4, 4}, {3, 5}, {20, 20},
 {8, 6}, {20, 13}, {17, 14}, {20, 20}, {11, 11}, {16, 19},
 {20, 13}, {16, 20}, {13, 13}, {10, 17}, {3, 4}, {18, 19}}

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Testing a random integer generator Clif McInnis <c_mcinnis@hotmail.com> - 2013-04-07 01:55 +0000
  Re: Testing a random integer generator Peter Pein <petsie@dordos.net> - 2013-04-08 04:06 +0000
  Re: Testing a random integer generator (Answered) Clif McInnis <c_mcinnis@hotmail.com> - 2013-04-08 04:05 +0000
  Re: Testing a random integer generator Peter Pein <petsie@dordos.net> - 2013-04-08 04:06 +0000
  Re: Testing a random integer generator Clif McInnis <c_mcinnis@hotmail.com> - 2013-04-09 08:04 +0000
  Re: Testing a random integer generator Ray Koopman <koopman@sfu.ca> - 2013-04-09 08:04 +0000

csiph-web