       Re: Can this be made cleaner and more efficient?

• To: mathgroup at smc.vnet.net
• Subject: [mg29047] Re: Can this be made cleaner and more efficient?
• From: "Orestis Vantzos" <atelesforos at hotmail.com>
• Date: Sat, 26 May 2001 21:53:37 -0400 (EDT)
• Organization: National Technical University of Athens, Greece
• References: <9eksm9\$7r9@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```This function test[n_], checks checks the factors of n,
With[{primes = Array[Prime, {24}]},
test[res_] := Or @@ (Outer[Mod[#1, #2] == 0 &, {res}, primes] // Flatten)]

Now you can use this:
myRand[d_] :=
NestWhile[Random[Integer, 10^(d - 1), 10^d}] &, 2, test, 1]

"Flip" <nospam at newsranger.com> wrote in message
news:9eksm9\$7r9 at smc.vnet.net...
> Hi All,
>
> I was wondering if the following module (it is small) can be made simpler
and
> faster ... and thoughts would be appreciated.
>
> RandomOdd2[d_] := Module[{res},
> res = Random[Integer, {10^(d - 1), 10^d}];
> While[(
>
> Mod[res, 02] == 0 || Mod[res, 03] == 0 || Mod[res, 05] == 0 ||
> Mod[res, 07] == 0 || Mod[res, 11] == 0 || Mod[res, 13] == 0 ||
> Mod[res, 17] == 0 || Mod[res, 19] == 0 || Mod[res, 23] == 0 ||
> Mod[res, 29] == 0 || Mod[res, 31] == 0 || Mod[res, 37] == 0 ||
> Mod[res, 41] == 0 || Mod[res, 43] == 0 || Mod[res, 47] == 0 ||
> Mod[res, 53] == 0 || Mod[res, 59] == 0 || Mod[res, 61] == 0 ||
> Mod[res, 71] == 0 || Mod[res, 73] == 0 || Mod[res, 79] == 0 ||
> Mod[res, 83] == 0 || Mod[res, 89] == 0 || Mod[res, 97] == 0),
> res = Random[Integer, {10^(d - 1), 10^d}]];
> res]
>
> It is basically sieving out the first 24 primes (primes <= 100) from the
result.
>
> Thank you ... Flip
>
>

```

• Prev by Date: RE: Converting from string to integer and back
• Next by Date: Re: Showing intermediate steps in calculations
• Previous by thread: Can this be made cleaner and more efficient?
• Next by thread: Re: Can this be made cleaner and more efficient?