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.
subtype Element_Type is Integer;
type List_Type is array (Positive range <>) of Element_Type;
function Pick_Random (X : List_Type) return Element_Type is
subtype Index_Range is Positive range X'Range;
package Random_Index is new
Ada.Numerics.Discrete_Random (Index_Range);
Generator : Random_Index.Generator;
begin
Random_Index.Reset (Generator);
return X (Random_Index.Random (Generator));
end Pick_Random;
(rand-nth x)
x[new Random().nextInt(x.length)];
Enum.random(x)
lists:nth(rand:uniform(length(X)), X).
call random_number (a)
x(lbound(x) + int(a*ubound(x))
func pick[T any](x []T) T {
return x[rand.Intn(len(x))]
}
x.shuffled().first()
x[Math.floor(Math.random() * x.length)]
x[~~(Math.random() * x.length)];
x.get((int)(Math.random()*x.size()))
list.random()
(nth (random (length x)) x)
x[math.random(#x)]
x[arc4random_uniform(x.count)]
$x[ array_rand($x) ]
element := x[random(length(x))];
my @x = ('a', 'list', 'of', 'random', 'items');
print $x[rand @x];
x.sample
(list-ref x (random (length x)))
x atRandom