New answers tagged

0 votes

Randomize the scalars of an array

RProgN 2, 3 bytes 0Rñ Explained 0Rñ 0R # Range of numbers 0-n (Implicit input) ñ # Shuffle, Implicit output. Try it online!
ATaco's user avatar
  • 10.2k
0 votes

Output a random unary string

Volatile, 7 bytes ~(:-.~) Assumes that the . instruction is present in the interpreter. Prints a random length of ...
bluswimmer's user avatar
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
0 votes

Be big more often

MathGolf, 4 bytes ‼ww╙ Try it online. Port of @DominicVanEssen's second R answer. Explanation: ...
Kevin Cruijssen's user avatar
0 votes

Be big more often

05AB1E, 5 bytes {.s˜Ω Try it online. Or alternatively, a port of @DominicVanEssen's second R answer is 5 bytes as well: ΩIΩ‚à ...
Kevin Cruijssen's user avatar
0 votes

Be big more often

JavaScript (V8), 53 bytes a=>Math.max(...a.map(_=>a[a.length*Math.random()|0])) Try it online! Not best now though
l4m2's user avatar
  • 19.1k
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

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
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
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,165
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.9k
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
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
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
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,721
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
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.5k
1 vote

Be big more often

Vyxal, 3 bytes øḊ℅ Try it Online! Explained ...
lyxal's user avatar
  • 31.4k
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
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

Top 50 recent answers are included