Can this be made cleaner and more efficient?
- To: mathgroup at smc.vnet.net
- Subject: [mg29022] Can this be made cleaner and more efficient?
- From: Flip <nospam at newsranger.com>
- Date: Fri, 25 May 2001 01:47:58 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
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