# 10 print chr$(205.5+rnd(1)); : goto 10

**URL:** <https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483>\
**Category:** Coding Questions\
**Created:** [November 14, 2019, 10:30am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483 "2019-11-14T10:30:45Z")\
**Posts on this page:** 18\
**Page:** 4

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [August 20, 2021, 5:08pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/63 "2021-08-20T17:08:29Z")

</div>

OK. Here goes: [Is there an elegant way to generate the permutations of all the members of a set?](https://discourse.processing.org/t/is-there-an-elegant-way-to-generate-the-permutations-of-all-the-members-of-a-set/31810)

@jeremydouglass

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 18, 2024, 10:50am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/64 "2024-06-18T10:50:42Z")

</div>

Almost 3 years later!

Leaner (108 characters) than [my last version](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/55) (113 characters).

```auto
size(530,530);for(int i=0,y=0,n=23;i<n*n;i++){int r=(int)random(2)*n,x=i%n*n;y=i/n*n;line(x+r,y,x+n-r,y+n);}

```

```auto
size(530, 530);
for(int i=0, y=0, n=23; i<n*n; i++)
  {
  int r=(int)random(2)*n, x=i%n*n;
  y=i/n*n;
  line(x+r, y, x+n-r, y+n); 
  }

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/4/7/47323940a0d93c6c9980c22ba71dc13f5d8ff813.png)

Another variation at 108 characters:

```auto
size(530,530);int i=0,n=23;while(i<n*n){int r=(int)random(2)*n,x=i%n*n;int y=i++/n*n;line(x+r,y,x+n-r,y+n);}

```

```auto
size(530, 530);
int i=0, n=23;  
while(i<n*n)
  {
  int r=(int)random(2)*n, x=i%n*n;
  int y=i++/n*n;
  line(x+r, y, x+n-r, y+n);
  }

```

And yet another version at 104 characters!

```auto
size(530,530);int i=0,n=23;while(i<n*n){int r=(int)random(2)*n,x=i%n*n,y=i++/n*n;line(x+r,y,x+n-r,y+n);}

```

```auto
size(530, 530);
int i=0, n=23;  
while(i<n*n)
  {
  int r=(int)random(2)*n, x=i%n*n, y=i++/n*n;
  line(x+r, y, x+n-r, y+n);
  }

```

I will come back in 3 years to revisit this! Maybe sooner… `:)`

> **[Why You Should Take a Break from Coding](https://medium.com/@robertfkillion/why-you-should-take-a-break-from-coding-547d026592d6)**
>
> Learning to code is deeply challenging, deeply rewarding, and can completely hijack your attention… You need to take a break.

Back…

This version has 103 characters:

```auto
size(530, 530);for(int j=0,m=23;j<m*m;){int r=(int)random(2)*m,x=j%m*m,y=j++/m*m;line(x+r,y,x+m-r,y+m);}  

```

```auto
size(530, 530);  
for(int j=0, m=23; j<m*m;)
  {
  int r=(int)random(2)*m, x=j%m*m, y=j++/m*m;
  line(x+r, y, x+m-r, y+m);
  }

```

`:)`

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [June 19, 2024, 6:09am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/67 "2024-06-19T06:09:26Z")

</div>

100 char:

```processing
size(530,530);for(int j=-1,m=23,r=0;j<530;r=random(2)>1?m:0)line(j%m*m+r,j/m*m,j%m*m+m-r,j++/m*m+m);  

```

which is

```processing
size(530,530);
for(int j=-1, m=23, r=0; j<530; r=random(2)>1?m:0)
  line(j%m*m+r, j/m*m, j%m*m+m-r, j++/m*m+m);

```

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [June 19, 2024, 6:38am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/68 "2024-06-19T06:38:33Z")

</div>

109 char (p5js)

```javascript
setup=_=>{for(createCanvas(M=530,M),j=0,m=23;j<M;)r=random([0,m]),x=j%m*m,line(x+r,y=int(j++/m)*m,x+m-r,y+m)}

```

```javascript
setup=_=>{
  for(createCanvas(M=530,M),j=0,m=23;j<M;)
    r=random([0,m]),
    x=j%m*m,
    line(x+r,y=int(j++/m)*m,x+m-r,y+m)
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 19, 2024, 7:27am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/69 "2024-06-19T07:27:38Z")

</div>

@micuat Nice!

99 char:

```auto
size(530,530);for(int j=0,m=23,r=0;j<m*m;r=random(2)>1?m:0)line(j%m*m+r,j/m*m,j%m*m+m-r,j++/m*m+m);

```

```auto
size(530, 530);
for(int j=0, m=23, r=0; j<m*m; r=random(2)>1?m:0)
  line(j%m*m+r, j/m*m, j%m*m+m-r, j++/m*m+m);

```

You can see the symmetry with this code I used for testing:

```auto
size(550, 550);
translate(10, 10);

//size(530, 530);
for(int j=0, m=23, r=0; j<m*m; r=random(2)>1?m:0)
  {
  //r=m; //or r=0 for testing
  line(j%m*m+r, j/m*m, j%m*m+m-r, j++/m*m+m);
  println(j, j%m, j/m);
  }

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/f/0/f06385feed76bd86147cd8a60f9d8c193aba58e5.png)

`:)`

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [June 19, 2024, 7:58am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/70 "2024-06-19T07:58:13Z")

</div>

thanks! I left `j=-1` just because the angle of the first slash is always determined if you start with `j=0`.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 22, 2024, 11:23am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/71 "2024-06-22T11:23:53Z")

</div>

Hello,

The _choice()_ function may also be used in some of the examples already provided.

The _choice()_ function is not in the on-line references but can be found in the source code.

If the end goal is to shorten the code for [code golf](https://en.wikipedia.org/wiki/Code_golf) this will certainly do the task!

Each of these performs the same task :

```auto
int n = 23;
int r = 0;
r=choice(2);
r=(int)random(2);
r=random(2)>1?1:0;

```

Example of maze with output to sketch window and also the console:

```auto
/*
 Project: Maze (10 print chr$(205.5+rnd(1)); : goto 10)
 Author: GLV
 Date: 2024-06-20
 Version: 1.0.0
*/

size(550, 550);
translate(10, 10);

int n = 23;
int r;

stroke(0);
rect(0, 0, n*n, n*n);

for(int j=0; j<n*n; j++)
  {    
  r = choice(2);  
    
  // These all return a random 0 or 1.
  // Aligned to compare size:  
  // r=choice(2);
  // r=(int)random(2);   
  // r=random(2)>1?1:0;  
  
  int x = j%n;
  int y = j/n;
  
  if (j%(23) == 0) println();
  if (r == 1) print('/');
  if (r == 0) print('\\');
  
  r = r*n; 
  x = x*n;
  y = y*n;
  
  line(x+r, y, x+n-r, y+n);
  }

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/a/1/a1851f2beb0435d17ecba548db96f4bfe0ea9487.png)

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/8/f/8fc352662effc8fc474d3356c3faaf3bd9a6b9e7.png)

Reference to _choice()_ in Processing source code:

> <https://github.com/benfry/processing4/blob/main/core/src/processing/core/PApplet.java#L4795>

`:)`

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 22, 2024, 12:09pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/72 "2024-06-22T12:09:03Z")

</div>

Shaved off a few characters.

This has 95 characters:

```auto
size(530,530);for(int j=0,m=23,r=0;j<m*m;r=choice(2)*m)line(j%m*m+r,j/m*m,j%m*m+m-r,j++/m*m+m);

```

First diagonal line is not random; feel free (anyone) to modify.

That was fun!

`:)`

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [June 22, 2024, 8:17pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/73 "2024-06-22T20:17:37Z")

</div>

wow amazing!! the only improvement I can think of is to get rid of `size()`

81 char (lines do fill the canvas)

```processing
for(int j=0,m=10,r=0;j<100;r=choice(2)*m)line(j%m*m+r,j/m*m,j%m*m+m-r,j++/m*m+m);

```

75 char (lines don’t fill the canvas)

```processing
for(int j=0,r=0;j<81;r=choice(2)*9)line(j%9*9+r,j/9*9,j%9*9+9-r,j++/9*9+9);

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 22, 2024, 10:56pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/74 "2024-06-22T22:56:04Z")

</div>

> [@micuat](#):
>
> the only improvement I can think of is to get rid of `size()`

It should not be so small that the maze is not a challenge or a poor presentation.

This may be a compromise and still keep it small (for that challenge):

```auto
println(g.width, g.height);

println(100/81.0); //1.234567890123... How cool is that!
println(10/8.1); // Curious! 
//size(100,100);
  scale(1.2345); // Number of decimal places can be reduced
//scale(10/8.1);
for (int j=0, r=0; j<81; r=choice(2)*9)
  {  
  line(j%9*9+r, j/9*9, j%9*9+9-r, j++/9*9+9);
  }

```

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/8/6/86e8c5bea11861f10e0e2140ea9f7655980ee07d.png)

I came across this discussion related to 100/81:  
[https://www.reddit.com/r/askmath/comments/1byjkbe/100\_8100\_00123456789\_repeating/?rdt=44218](https://www.reddit.com/r/askmath/comments/1byjkbe/100_8100_00123456789_repeating/?rdt=44218)

Math and coding is just so much fun!

`:)`

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 23, 2024, 11:57am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/75 "2024-06-23T11:57:13Z")

</div>

Hello again!

I tried with p5.js and [your code example](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/68) to start with and bit manipulation to replace % and /.

110 characters:

```auto
m=16;setup=_=>{for(createCanvas(n=m*m,n),j=0;j<n;)r=random([0,m]),x=j&15,line(x*m+r,y=(j++>>4)*m,x*m+m-r,y+m)}

```

```auto
m=16;
setup=_=>
  {
  for(createCanvas(n=m*m,n),j=0;j<n;)
  r=random([0,m]),
  
  x=j&15,
  line(x*m+r,y=(j++>>4)*m,x*m+m-r,y+m)
  
  // Not shorter:
  //x=(j&15)*m,
  //line(x+r,y=(j++>>4)*m,x+m-r,y+m)    
  }

```

I thought I may be able to take advantage of bit manipulation to code golf (shorten) the code.

`:)`

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [June 23, 2024, 12:20pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/76 "2024-06-23T12:20:33Z")

</div>

great! m=16 can go inside random

108

```javascript
setup=_=>{for(createCanvas(n=256,n),j=0;j<n;)r=random([0,m=16]),x=j&15,line(x*m+r,y=(j++>>4)*m,x*m+m-r,y+m)}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 23, 2024, 3:52pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/77 "2024-06-23T15:52:53Z")

</div>

Hello,

p5.js version with bit manipulation and createCanvas() removed.

94 characters

```auto
n=256;setup=_=>{for(j=0;j<n;)r=random([0,m=6.25]),x=j&15,line(x*m+r,y=(j++>>4)*m,x*m+m-r,y+m)}

```

```auto
n=256;
setup=_=>{
  // console.log(width, height); 100x100
  for(j=0;j<n;)
  r=random([0,m=6.25]), //100/16 = 6.25
  x=j&15,
  line(x*m+r,y=(j++>>4)*m,x*m+m-r,y+m)
}

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/4/0/40958e1f4087691b65aac4b858500e4cec66d40a.png)

`:)`

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [June 23, 2024, 4:45pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/78 "2024-06-23T16:45:00Z")

</div>

Cool!! I think n is not needed anymore

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 24, 2025, 1:24am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/79 "2025-08-24T01:24:53Z")

</div>

Hello,

> [@micuat](#):
>
> Cool!! I think n is not needed anymore

90 characters!

```auto
setup=_=>{for(j=0;j<256;)r=random([0,m=6.25]),x=j&15,line(x*m+r,y=(j++>>4)*m,x*m+m-r,y+m)}

```

Note:

```auto
// Note:
// Default screen size is 100x100
// Grid is 16x16
// Spacing is 100/16 = 6.25
// You can modify the 6.25 but it was left as is for correct spacing.

r=random([0,m=6.25]), //100/16 = 6.25

```

p5.js:

> **[p5.js](https://p5js.org/)**
>
> p5.js

Start Coding:

> **[p5.js Web Editor](https://editor.p5js.org/)**
>
> A web editor for p5.js, a JavaScript library with the goal of making coding accessible to artists, designers, educators, and beginners.

`:)`

---

<div class="post-metadata">

**Author:** ![paulstgeorge](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@paulstgeorge](https://discourse.processing.org/u/paulstgeorge)\
**Post date:** [August 24, 2025, 5:44am UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/80 "2025-08-24T05:44:28Z")

</div>

> [@glv](#):
>
> `setup=_=>{for(j=0;j<256;)r=random([0,m=6.25]),x=j&15,line(x*m+r,y=(j++>>4)*m,x*m+m-r,y+m)`}

This is javascript, right?

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 24, 2025, 12:05pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/81 "2025-08-24T12:05:27Z")

</div>

> [@paulstgeorge](#):
>
> This is javascript, right?

It is for p5.js! I updated my post.

`:)`

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [March 15, 2026, 9:46pm UTC](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483/82 "2026-03-15T21:46:55Z")

</div>

Hello folks!

_ **88 characters** _ now!  
Looped it backwards for this version.  
_I did not modify the spacing of 6.25; this will reduce it by 3 characters._

```javascript
setup=_=>{for(j=256;j--;)r=random([0,m=6.25]),x=j&15,line(x*m+r,y=(j>>4)*m,x*m+m-r,y+m)}

```

Note:

```auto
// Default screen size is 100x100
// Grid is 16x16
// Spacing is 100/16 = 6.25
// The 6.25 was use to fill the 100x100 grid
// m=6 makes each grid cell 6 pixels wide and tall, so the 16×16 tile maze becomes 96×96 instead of 100x100 total size.

//r=random([0,m=6.25]), //100/16 = 6.25

```

Modified only to update every 2 secs:

https://editor.p5js.org/glv/embed/IX6U4SeND

`:)`

[Previous page](https://discourse.processing.org/t/10-print-chr-205-5-rnd-1-goto-10/15483.md?page=3)
