Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Finding a relative prime

  • To: mathgroup at
  • Subject: [mg19696] Re: [mg19682] Finding a relative prime
  • From: "Andrzej Kozlowski" <andrzej at>
  • Date: Sat, 11 Sep 1999 16:36:03 -0400
  • Sender: owner-wri-mathgroup at

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:


Andrzej Kozlowski
Toyama International University

>From: Timur Tabi <nospam_timur at>
>To: mathgroup at
>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
> Sent via
> Share what you know. Learn what you don't.

  • Prev by Date: direction field plots
  • Next by Date: PDE solver problems
  • Previous by thread: RE: Finding a relative prime
  • Next by thread: Re: Finding a relative prime