Uploaded December 2024 | Updated December 2026, 3 hours ago
The WeightedIntegerSequence is a SequenceGenerator whose next() method returns a randomly chosen integer 0..N-1 whose probabilities of being chosen are weighted by an array of length N. So with an array { 1, 1 } would
return 0 roughly half the time, and 1 roughly half the time. The array { 2, 0, 1 } would return 0 roughly 2/3 of the time, would never return 1, and would return 2 roughly 1/3 of the time.
This example uses a WeightedIntegerSequence to generate a random walk, where the intervals -1, 0, and 1 are weighted. The user can control the
weighting by entering new relative weights in the TextFields and clicking the "apply" button.
Thanks to Larry Polansky for suggesting that WeightedIntegerSequence be part of JMSL.
The WeightedIntegerSequence is a SequenceGenerator whose next() method returns a randomly chosen integer 0..N-1 whose probabilities of being chosen are weighted by an array of length N. So with an array { 1, 1 } would
return 0 roughly half the time, and 1 roughly half the time. The array { 2, 0, 1 } would return 0 roughly 2/3 of the time, would never return 1, and would return 2 roughly 1/3 of the time.
This example uses a WeightedIntegerSequence to generate a random walk, where the intervals -1, 0, and 1 are weighted. The user can control the
weighting by entering new relative weights in the TextFields and clicking the "apply" button.
Thanks to Larry Polansky for suggesting that WeightedIntegerSequence be part of JMSL.










