Random - Better Random Number Generation for Grails

  • Authors : Jonathan Griggs
0 vote
Dependency :
compile ":random:0.2"
Custom repositories :
mavenRepo "http://grails.org/plugins"

Documentation

Summary

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

Installation

grails install-plugin random

Description

Random - Better Random Number Generation for Grails

Description

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 java.security.SecureRandom. 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.

Installation

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:

http://localhost:8080/myAppContext/random

Documentation

The official documentation for the Random plugin may be found at https://github.com/boatmeme/grails-random

Source Code

The source code is available on GitHub at https://github.com/boatmeme/grails-random.

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

git clone git://github.com/boatmeme/grails-random

Contributions welcome!

Issue Tracking

Issue tracking is also on GitHub at https://github.com/boatmeme/grails-random/issues.

Bug reports, Feature requests, and general inquiries welcome.

Contact

Feel free to contact me by email (jonathan.griggs at gmail.com) or follow me on GitHub at https://github.com/boatmeme.

Roadmap

Future versions should include:

  • Ability to reseed the PRNGs
  • Ability to specify the SeedGenerator to use (i.e. Random.org, /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