aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/jsyn/util
diff options
context:
space:
mode:
authorPhil Burk <[email protected]>2015-01-31 18:32:50 -0800
committerPhil Burk <[email protected]>2015-01-31 18:32:50 -0800
commitefc7fc30ba074c687644f2f4c66c4b1c950da9c5 (patch)
tree496faa82295838ccb1d68d16642bcc892ca94e4c /src/com/jsyn/util
parentdd9e0cdf6475034f538dc5b925a1ba6f1076761e (diff)
Added a new BrownNoise unit generator that generate
noise based on Brownian motion.
Diffstat (limited to 'src/com/jsyn/util')
-rw-r--r--src/com/jsyn/util/PseudoRandom.java12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/com/jsyn/util/PseudoRandom.java b/src/com/jsyn/util/PseudoRandom.java
index b7f619c..7fcb1f4 100644
--- a/src/com/jsyn/util/PseudoRandom.java
+++ b/src/com/jsyn/util/PseudoRandom.java
@@ -48,7 +48,7 @@ public class PseudoRandom {
}
public void setSeed(int seed) {
- this.seed = ((long) seed) & 0xFFFFFFFF;
+ this.seed = (long) seed;
}
public int getSeed() {
@@ -76,14 +76,14 @@ public class PseudoRandom {
/** Calculate random 32 bit number using linear-congruential method. */
public int nextRandomInteger() {
- long rand = (seed * 196314165) + 907633515;
- seed = rand & 0x00000000FFFFFFFFL;
- return (int) rand;
+ // Use values for 64-bit sequence from MMIX by Donald Knuth.
+ seed = (seed * 6364136223846793005L) + 1442695040888963407L;
+ return (int) (seed >> 32); // The higher bits have a longer sequence.
}
public int choose(int range) {
- long bigRandom = nextRandomInteger() & 0x7FFFFFFF;
- long temp = bigRandom * range;
+ long positiveInt = nextRandomInteger() & 0x7FFFFFFF;
+ long temp = positiveInt * range;
return (int) (temp >> 31);
}
}