Re: Finding a relative prime

*To*: mathgroup at smc.vnet.net*Subject*: [mg19696] Re: [mg19682] Finding a relative prime*From*: "Andrzej Kozlowski" <andrzej at tuins.ac.jp>*Date*: Sat, 11 Sep 1999 16:36:03 -0400*Sender*: owner-wri-mathgroup at wolfram.com

One way to do this (modulo the well known limitation of PrimeQ) is: randompick[q_?PrimeQ] := Module[{l}, (l = Select[Range[2, q - 1], PrimeQ])[[Random[ Integer, {1, Length[l]}]]]] For example: In[16]:= randompick[Prime[1000]] Out[16]= 59 -- Andrzej Kozlowski Toyama International University JAPAN http://sigma.tuins.ac.jp http://eri2.tuins.ac.jp ---------- >From: Timur Tabi <nospam_timur at tabi.org> >To: mathgroup at smc.vnet.net >Subject: [mg19696] [mg19682] Finding a relative prime >Date: Thu, Sep 9, 1999, 3:19 PM > > I'm using Mathematica 3.0 for the Mac, and I'm trying to figure out how > to get it to pick a random number that is relatively prime to another > number, p-1, where p is prime. In other words, pick a random number k > such that 1) k is between 2 and p-1, and 2) k is relatively prime to p-1. > How can I do that in Mathematica 3.0? > > -- > Remove "nospam_" from my email address when replying > Timur "too sexy for my code" Tabi, timur at tabi.org > > > Sent via Deja.com http://www.deja.com/ > Share what you know. Learn what you don't. > >