Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #14102
| From | Peter Pein <petsie@dordos.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Testing a random integer generator |
| Date | 2013-04-08 04:06 +0000 |
| Message-ID | <kjtfnm$du5$1@smc.vnet.net> (permalink) |
| References | <kjqjln$37o$1@smc.vnet.net> |
| Organization | Time-Warner Telecom |
Am 07.04.2013 03:55, schrieb Clif McInnis:
> 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++]
>
I've got another one that generates the pairs very fast:
With[{disttbl =
MapAt[TransformedDistribution[{x, x}, x \[Distributed] #] &,
DiscreteUniformDistribution /@
Flatten[Table[
Flatten[Table[d, {d, {{1, 9}, {10, 20}}}, {n}], 2 - n],
{n, 2}], 1],
{{1}, {2}}]},
thedist = MixtureDistribution[{1, 3, 1, 3}, disttbl]];
rndPairs[n_] := Round@RandomVariate[thedist, n];
the "Round" is necessary because TransformedDistribution returns inexact
numbers (bug or feature?).
Have fun,
Peter
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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