# Check if variable is a prime

**URL:** https://discourse.processing.org/t/check-if-variable-is-a-prime/31216
**Category:** Coding Questions
**Created:** [July 12, 2021, 9:24pm UTC](https://discourse.processing.org/t/check-if-variable-is-a-prime/31216 "2021-07-12T21:24:18Z")
**Posts on this page:** 5
**Page:** 2

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [July 13, 2021, 7:27pm UTC](https://discourse.processing.org/t/check-if-variable-is-a-prime/31216/21 "2021-07-13T19:27:57Z")

</div>

no, i saw a shuffle thing and wanted to recreate it as close to reality as possible

---

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [July 13, 2021, 7:42pm UTC](https://discourse.processing.org/t/check-if-variable-is-a-prime/31216/22 "2021-07-13T19:42:49Z")

</div>

actually i just found a way to do it. here it is:

int all= 100;  
int x= (int(random(all-1)));  
int y= all-x;

void setup(){  
size(100, 100);  
print(x);}

void draw(){  
background(255,255,255);  
fill(0,0,0);  
if(all/2==x){  
stop();}

if(x\<y){x=x+1; y=y-1;}  
if(y\<x){y=y+1; x=x-1;}  
ellipse(x,y,25,25);  
}

---

<div class="post-metadata">

### Author: ![javagar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/javagar/32/11434_2.png) [@javagar](https://discourse.processing.org/u/javagar)
#### Post date: [July 13, 2021, 7:45pm UTC](https://discourse.processing.org/t/check-if-variable-is-a-prime/31216/23 "2021-07-13T19:45:15Z")

</div>

Does this still relate to the prime number function?

---

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [July 13, 2021, 7:46pm UTC](https://discourse.processing.org/t/check-if-variable-is-a-prime/31216/24 "2021-07-13T19:46:11Z")

</div>

> [@MoonAlien822](#):
>
> int all= 100;  
> int x= (int(random(all-1)));  
> int y= all-x;
> 
> void setup(){  
> size(100, 100);  
> print(x);}
> 
> void draw(){  
> background(255,255,255);  
> fill(0,0,0);  
> if(all/2==x){  
> stop();}
> 
> if(x\<y){x=x+1; y=y-1;}  
> if(y\<x){y=y+1; x=x-1;}  
> ellipse(x,y,25,25);  
> }

no this method doesn’t need to change anything if it sees a prime number because it subtracts instead of deviding

---

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [July 13, 2021, 7:47pm UTC](https://discourse.processing.org/t/check-if-variable-is-a-prime/31216/25 "2021-07-13T19:47:01Z")

</div>

thank you to e everyone who helped me

[Previous page](https://discourse.processing.org/t/check-if-variable-is-a-prime/31216.md?page=1)
