Some simple randomization code for JavaScript