Fixing issue #11: generating random integers correctly

I just copy/pasted the function from MDN - it may as well be simplified for the purposes of this particular lib.