Polyglot CheatSheet - Random

Updated: 2018-06-18

Java

Random random = new Random(System.currentTimeMillis())

Javascript

Generate a random number between 0 and 1:

Math.random()

Generate a random integer:

function getRandomInt(max) {
  return Math.floor(Math.random() * max);
}

Python

>>> import random
>>> random.random()
0.12062307072338296