Uncommons Maths is a java library with nice math utilities and random number generators. This requires the library uncommons-maths-1.2.2.jar to be in classpath. The following example shows using DiscreteUniformGenerator class.
package com.bethecoder.tutorials.uncommons; import java.util.Random; import org.uncommons.maths.random.DiscreteUniformGenerator; public class DiscreteUniformGeneratorTest { /** * @param args */ public static void main(String[] args) { DiscreteUniformGenerator rand = new DiscreteUniformGenerator(20, 40, new Random()); for (int i = 0 ; i < 10 ; i ++) { System.out.println(rand.nextValue()); } } }
29 30 39 31 21 33 37 22 23 32