Programming-Idioms

Implementation
Lisp

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating resource.

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

Implementation edit is for fixing errors and enhancing with metadata.

Instead of changing the code of the snippet, consider creating another Lisp implementation.

Other implementations
x.get((int)(Math.random()*x.size()))
x[Math.floor(Math.random() * x.length)]
import random
random.choice(x)
import "math/rand"
x[rand.Intn(len(x))]
#include <stdlib.h>
x[rand() % x_length];
$x[ array_rand($x) ]
my @x = ('a', 'list', 'of', 'random', 'items');
print $x[rand @x];
import std.random;
x.randomSample(1);
x[new Random().nextInt(x.length)];
element := x[random(length(x))];
uses classes;
element := x.Items[random(x.count)];
import System.Random (randomR)
(\l g -> l !! fst (randomR (0, length l) g))
Enum.random(x)
https://github.com/inaka/erlang-katana
ktn_random:pick(X)
lists:nth(rand:uniform(length(X)), X).
x[math.random(#x)]
x.sample
import scala.util.Random
val x = List(1, 2, 3, 4)
x.apply(Random.nextInt(x.size))
using System;
using System.Collections.Generic;
x[new Random().Next(x.Count)];
import "math/rand"
func pickT(x []T) T {
	return x[rand.Intn(len(x))]
}
use rand::{self, Rng};
x[rand::thread_rng().gen_range(0, x.len())]
(rand-nth x)
import System.Random (randomRIO)
(l !!) <$> randomRIO (0, length l - 1)
#include <random>
std::mt19937 gen;
std::uniform_int_distribution<size_t> uid (0, x.size () - 1);
x[uid (gen)];
extern crate rand;
use rand::{thread_rng, Rng};
let choice = thread_rng().choose(&x).unwrap();
import java.util.concurrent.ThreadLocalRandom;
x.get(ThreadLocalRandom.current().nextInt(0, x.size()))
(nth (random (length x)) x)
list.random()
call random_number (a)
x(lbound(x) + int(a*ubound(x))
const x = [1, 'two', 3, 4, 'five', 'six', 7, 8, 'nine' ];

const randomElement = x[~~(Math.random() * x.length)];