Logo

Programming-Idioms

Assign to the integer x a random number between 0 and 17 (inclusive), from a crypto secure random number generator.
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import "crypto/rand"
import "math/big"
bi, err := rand.Int(rand.Reader, big.NewInt(18))
x := int(bi.Int64())
$x = random_int(0, 17)
use Math::Random::Secure qw(irand);
my $x = irand(17);
use Math::Random::Secure qw(rand);
my $x = int(rand(17));
import secrets
x = secrets.choice(range(0, 18))
import secrets
x = secrets.randbelow(18)
require 'securerandom'
x = SecureRandom.rand(0..17)
use rand::prelude::*;
let mut rng = rand::thread_rng();
let x = rng.gen_range(0..18);