[Date Index]
[Thread Index]
[Author Index]
Re: Testing a random integer generator
*To*: mathgroup at smc.vnet.net
*Subject*: [mg130404] Re: Testing a random integer generator
*From*: Ray Koopman <koopman at sfu.ca>
*Date*: Tue, 9 Apr 2013 04:06:20 -0400 (EDT)
*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com
*Delivered-to*: l-mathgroup@wolfram.com
*Delivered-to*: mathgroup-newout@smc.vnet.net
*Delivered-to*: mathgroup-newsend@smc.vnet.net
*References*: <kjqjln$37o$1@smc.vnet.net>
On Apr 6, 6:55 pm, Clif McInnis <c_mcin... at 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}}
Prev by Date:
**Re: Testing a random integer generator**
Next by Date:
**Simplify a complex expression**
Previous by thread:
**Re: Testing a random integer generator**
Next by thread:
**Re: Testing a random integer generator (Answered)**
| |