Hot answers tagged

25 votes

Be big more often

Python, 41 bytes lambda l:choices(l,l) from random import* Attempt This Online! or run it 100000 times Uses the list itself as the weights.
MTN's user avatar
  • 761
14 votes

Be big more often

R, 27 bytes (Or 20 bytes in R>=4.1 using \ instead of function) ...
Dominic van Essen's user avatar
11 votes

Be big more often

Python, 64 bytes (also supports negative numbers) lambda l:sorted(l)[int(len(l)*random()**.5)] from random import* Attempt This Online! Explanation Sort the list, ...
bsoelch's user avatar
  • 4,653
8 votes

Be big more often

J, 8 bytes #~{~1?+/ Attempt This Online! 1?+/ Sum the numbers and then choose a random index between 0 and the sum ...
Jonah's user avatar
  • 32.4k
7 votes

Be big more often

Vyxal, 4 bytes ℅?℅∴ Try it Online! Return the highest of two random picks ...
Dominic van Essen's user avatar
7 votes

Be big more often

JavaScript (Node.js), 41 bytes a=>a.sort()[a.length*Math.random()**.5|0] Try it online! or run it 100000 times Takes an ...
MTN's user avatar
  • 761
6 votes

Be big more often

WolframLanguage, 63 48 bytes Thanks to att for shaving of 15 Sort[#][[Floor@Log2[Random[](2^Tr[1^#]2-3)+2]]]& Original answer: ...
infinitezero's user avatar
  • 1,637
5 votes

Be big more often

Ruby, 32 24 bytes ->l{(l+l).sample(2).max} Try it online! Thanks to Dominic van Essen for -4 bytes and the idea to get to -8.
G B's user avatar
  • 20.8k
4 votes

Be big more often

JavaScript (Node.js), 58 bytes a=>a.sort((a,b)=>b-a).filter(_=>Math.random()<.5)[0]||a[0] Try it online! Sorts the numbers, filters them randomly, ...
Joyal Mathew's user avatar
4 votes

Be big more often

Charcoal, 10 bytes FAFι⊞υιI‽υ Try it online! Link is to verbose version of code. Explanation: FA Loop over the input numbers. <...
Neil's user avatar
  • 163k
4 votes

Be big more often

Wolfram Language (Mathematica), 19 bytes RandomChoice[#->#]& Try it online! Like other languages, the builtin can use weights, so the input can serve as the ...
Greg Martin's user avatar
  • 15.4k
4 votes

Be big more often

Jelly, 3 bytes X»X Attempt This Online! Distribution over 1000 runs: Attempt This Online! Uses Dominic van Essen's insight: pick a random element (...
pxeger's user avatar
  • 23.2k
4 votes

Be big more often

Raku, 13 bytes *.roll(2).max Attempt This Online! Picks two elements independently and returns the max of the two.
Jo King's user avatar
  • 47k
3 votes

Be big more often

Julia, 37 bytes !l=rand([fill.(sort(l),keys(l))...;]) Attempt This Online! sort the list and repeat each element by their index before randomly choosing a number ...
MarcMush's user avatar
  • 6,155
3 votes

Be big more often

Factor, 35 bytes [ [ dup <array> ] map-flat random ] Attempt This Online! Create n copies of each n, and select one at random (uniformly). For instance, <...
chunes's user avatar
  • 20.8k
3 votes

Be big more often

Jelly, 4 bytes ṢxJX A monadic Link that accepts a list of distinct floats and outputs a random one. Try it online! Or see the results of 10,000 runs. How? Weights ...
Jonathan Allan's user avatar
1 vote

Be big more often

Vyxal, 3 bytes øḊ℅ Try it Online! Explained ...
lyxal's user avatar
  • 31.4k
1 vote

Make your code error, but only sometimes!

Volatile, 3 bytes ~~/ ~ pushes a random number onto the stack (which may include zero), and ...
bluswimmer's user avatar
1 vote

Randomize the scalars of an array

Arturo, 17 bytes $=>[shuffle@0..&] Try it! ...
chunes's user avatar
  • 20.8k
1 vote

Randomize the scalars of an array

Factor, 25 bytes [ dup [0,b] swap sample ] Try it online! ...
chunes's user avatar
  • 20.8k
1 vote

Randomize the scalars of an array

Thunno 2, 3 bytes Ėµr Try it online! Explanation ...
The Thonnu's user avatar
  • 17.5k

Only top scored, non community-wiki answers of a minimum length are eligible