Plugins You can find out about all the publicly available Grails plugins.

Random - Better Random Number Generation for Grails

  • Authors: Jonathan Griggs
0 vote
compile ":random:0.2"
Custom repositories:
mavenRepo ""



A plugin that wraps the high-performance, statistically sound Uncommons Maths Pseudorandom Number Generators


grails install-plugin random


Random - Better Random Number Generation for Grails


This Grails plugin wraps the high-performance, statistically sound Uncommons Maths Pseudo-Random Number Generators in convenient, easy-to-use services and taglibs.

Why would I use this?

You may be asking yourself why you would ever install a highly specialized plugin when you can easily get a random number using java.util.Random with a single line of code. Although java.util.Random may suffice for many every-day randomization use-cases, there are at least 3 primary considerations to weigh when choosing to use this plugin (or the Uncommons Maths library):

  1. Quality - java.util.Random, while relatively fast, is inferior in the random quality of the numbers it generates. Over large distributions it exhibits significant periodic behavior that shatters any illusion of randomness, rendering it unsuitable for industrial-strength randomization purposes. The Uncommons Maths library provides alternative algorithms that produce higher-quality random numbers than java.util.Random.
2. Speed - core Java contains an alternative to java.util.Random in While this class fills the quality gap, it does so at a cost - in speed. Using SecureRandom may be up to 60 times slower than java.util.Random. Again, this may be suitable for most casual random-number needs, but for industrial strength usage, it may well fall far short of performance requirements. The Uncommons Maths library provides alternative algorithms that all perform faster than SecureRandom.

3. Convenience - the Random Grails plugin provides a taglib and a service, making it dead simple to add industrial-strength randomization wherever your application should need it. If you've identified a need for shuffling lists, drawing random objects from a collection, or generating a random number from a specified range, you might as well do it the right way.

I found myself using Uncommons Maths for reasons 1 and 2 when it became clear that the core Java randoms would not suffice for my Random Bands experiment. I decided to package this as a plugin for reason #3 so that others might benefit.


Enter your application directory and run the following from the command line:

grails install-plugin random

After you have installed the Random plugin in your application, I'd recommend you point your browser to the Plugin test page to verify all is working and familiarize yourself with the functionality it provides:



The official documentation for the Random plugin may be found at

Source Code

The source code is available on GitHub at

Find a bug? Fork it. Fix it. Issue a pull request.

git clone git://

Contributions welcome!

Issue Tracking

Issue tracking is also on GitHub at

Bug reports, Feature requests, and general inquiries welcome.


Feel free to contact me by email (jonathan.griggs at or follow me on GitHub at


Future versions should include:

  • Ability to reseed the PRNGs
  • Ability to specify the SeedGenerator to use (i.e., /dev/null, and SecureRandom)
  • Services that expose the Probability Distribution Wrappers (Uniform, Normal, Binomial, Poisson and Exponential)

Change Log

v0.2 - 2012.05.15

  • Upgraded to Grails 2.0.3
  • Fixed compatibility with apps that do not use Hibernate - Set transactional = false in RandomService

v0.1 - 2011.06.17

  • Initial release