# How would I generate a random number coprime to another?

**URL:** <https://cl.desmos.com/t/how-would-i-generate-a-random-number-coprime-to-another/7966>\
**Category:** Questions\
**Created:** [June 3, 2025, 6:15pm UTC](https://cl.desmos.com/t/how-would-i-generate-a-random-number-coprime-to-another/7966 "2025-06-03T18:15:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lavender](https://avatars.discourse-cdn.com/v4/letter/l/51bf81/32.png) [@Lavender](https://cl.desmos.com/u/Lavender)\
**Post date:** [June 3, 2025, 6:15pm UTC](https://cl.desmos.com/t/how-would-i-generate-a-random-number-coprime-to-another/7966/1 "2025-06-03T18:15:05Z")

</div>

This is for a graph I am working on for Pallier encryption

---

<div class="post-metadata">

**Author:** ![Guzman\_Tierno](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/guzman_tierno/32/6149_2.png) [@Guzman\_Tierno](https://cl.desmos.com/u/Guzman_Tierno)\
**Post date:** [June 3, 2025, 6:53pm UTC](https://cl.desmos.com/t/how-would-i-generate-a-random-number-coprime-to-another/7966/2 "2025-06-03T18:53:04Z")

</div>

this uses a ticker …  
[https://www.desmos.com/calculator/agrwsefldo](https://www.desmos.com/calculator/agrwsefldo)

---

<div class="post-metadata">

**Author:** ![Guzman\_Tierno](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/guzman_tierno/32/6149_2.png) [@Guzman\_Tierno](https://cl.desmos.com/u/Guzman_Tierno)\
**Post date:** [June 3, 2025, 7:21pm UTC](https://cl.desmos.com/t/how-would-i-generate-a-random-number-coprime-to-another/7966/3 "2025-06-03T19:21:42Z")

</div>

this instead uses a direct approach (no Ticker) but it’s a bit more complex:  
[https://www.desmos.com/calculator/tdaxhbcgwh](https://www.desmos.com/calculator/tdaxhbcgwh)

It is made in such a way that all the numbers that are coprime with the given number  
have the same probability of being picked ..

---

<div class="post-metadata">

**Author:** ![NTMDev](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/ntmdev/32/7141_2.png) [@NTMDev](https://cl.desmos.com/u/NTMDev)\
**Post date:** [June 4, 2025, 3:41am UTC](https://cl.desmos.com/t/how-would-i-generate-a-random-number-coprime-to-another/7966/4 "2025-06-04T03:41:42Z")

</div>

Sorry if I seem like I’m intruding, I just saw this and was really interested in this question.  
I’ve never seen `random( )` passed without an argument! Does it act differently if you were to pass it with a range?

---

<div class="post-metadata">

**Author:** ![Guzman\_Tierno](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/guzman_tierno/32/6149_2.png) [@Guzman\_Tierno](https://cl.desmos.com/u/Guzman_Tierno)\
**Post date:** [June 4, 2025, 12:18pm UTC](https://cl.desmos.com/t/how-would-i-generate-a-random-number-coprime-to-another/7966/5 "2025-06-04T12:18:00Z")

</div>

Here’s the documentation on the various uses of the random function:  
[https://help.desmos.com/hc/en-us/articles/4405633253389-Statistics#h\_01FB2RSKNB6NT6P03Y9MXA0VX5](https://help.desmos.com/hc/en-us/articles/4405633253389-Statistics#h_01FB2RSKNB6NT6P03Y9MXA0VX5)

---

<div class="post-metadata">

**Author:** ![NTMDev](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/ntmdev/32/7141_2.png) [@NTMDev](https://cl.desmos.com/u/NTMDev)\
**Post date:** [June 4, 2025, 1:00pm UTC](https://cl.desmos.com/t/how-would-i-generate-a-random-number-coprime-to-another/7966/6 "2025-06-04T13:00:22Z")

</div>

Ohhhhhhh!!! Interesting, seems like `random` is default to generate between 0 and 1.

Cool! I didn’t know that before.

---

<div class="post-metadata">

**Author:** ![NTMDev](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/ntmdev/32/7141_2.png) [@NTMDev](https://cl.desmos.com/u/NTMDev)\
**Post date:** [June 4, 2025, 2:10pm UTC](https://cl.desmos.com/t/how-would-i-generate-a-random-number-coprime-to-another/7966/7 "2025-06-04T14:10:07Z")

</div>

Just curious but why do you need the coprimes?

oop sorry Guzman if this went to your email I meant to reply the post with through my email

---

<div class="post-metadata">

**Author:** ![Guzman\_Tierno](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/guzman_tierno/32/6149_2.png) [@Guzman\_Tierno](https://cl.desmos.com/u/Guzman_Tierno)\
**Post date:** [June 4, 2025, 3:31pm UTC](https://cl.desmos.com/t/how-would-i-generate-a-random-number-coprime-to-another/7966/8 "2025-06-04T15:31:27Z")

</div>

… no worries … 🙂 (some random words to fill the post)
