Skip to content

Commit 1e27600

Browse files
committed
adding choice() as an int alternative to random()
1 parent bc9696f commit 1e27600

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

core/src/processing/core/PApplet.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4830,6 +4830,26 @@ public final void randomSeed(long seed) {
48304830
}
48314831

48324832

4833+
/**
4834+
* Return a random integer from 0 up to (but not including)
4835+
* the specified value for “high”. This is the same as calling random()
4836+
* and casting the result to an <b>int</b>.
4837+
*/
4838+
public final int choice(int high) {
4839+
return (int) random(high);
4840+
}
4841+
4842+
4843+
/**
4844+
* Return a random integer from “low” up to (but not including)
4845+
* the specified value for “high”. This is the same as calling random()
4846+
* and casting the result to an <b>int</b>.
4847+
*/
4848+
public final int choice(int low, int high) {
4849+
return (int) random(low, high);
4850+
}
4851+
4852+
48334853

48344854
//////////////////////////////////////////////////////////////
48354855

core/todo.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ X https://github.com/processing/processing4/issues/544
1515
data
1616
X use choice() instead of random() for list classes
1717
X remove random(PApplet) since unlikely to be used/seems overkill
18-
_ add choice() as a PApplet method for int values of random()?
18+
X add choice() as a PApplet method for int values of random()
19+
1920

2021
contrib
2122
_ Loading SVG file gives Illegal base64 character 20 encoding error (worked in v3.5.4)
2223
_ https://github.com/processing/processing4/issues/592
2324
_ https://github.com/processing/processing4/issues/592
2425

25-
2626
_ freeze on resize with Windows (even the default renderer)
2727
_ https://github.com/processing/processing4/issues/507
2828

0 commit comments

Comments
 (0)