Pwxrand : Pwrand


Like Pwrand, outputs values randomly from a list according to a list of weights, but Pwxrand will never output the same list element twice in a row.


w = Pwrand((1..10), (1..10).reciprocal.normalizeSum, inf).asStream;

w.nextN(20);


[ 1, 1, 2, 2, 6, 10, 6, 1, 1, 7, 1, 2, 8, 1, 1, 2, 5, 1, 1, 2 ]


x = Pwxrand((1..10), (1..10).reciprocal.normalizeSum, inf).asStream;

x.nextN(20);


[ 1, 2, 7, 10, 3, 2, 1, 2, 8, 1, 7, 2, 10, 8, 2, 5, 3, 9, 1, 6 ]