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
  • 771
16 votes

XOR of independent Bernoulli variables

Haskell, 23 bytes foldr1$ \x p->x+p-2*p*x Try it online! If you have two events with probabilities x and ...
xnor's user avatar
  • 144k
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
  • 5,677
10 votes

Output a random value from the last 16 values outputted

Python, 102 88 86 85 84 bytes from random import*;*t,=range(16) while~-len({*(x:=t[-16:])}):t+=choice(x), print(t) Attempt This Online! -14 thanks to mousetail -1 ...
The Thonnu's user avatar
  • 17.8k
10 votes

Output a random value from the last 16 values outputted

Ruby, 55 51 48 bytes puts x=[*1..16];_,*x=x<<p(x.sample)while(x|x)[1] Try it online!
G B's user avatar
  • 21.3k
9 votes

Implement a bag without replacement

Vyxal, 5 bytes Inspired by Kevin Cruijssen's 05AB1E answer 6 bytes without the bonus: {7Þ℅⟑, Try it Online! Explanation ...
math scat's user avatar
  • 8,463
9 votes

XOR of independent Bernoulli variables

Python 2, 39 bytes x=0 for p in input():x+=p-x*p*2 print x Try it online! Also 39 bytes: ...
xnor's user avatar
  • 144k
8 votes

Implement a bag without replacement

R, 50 40 bytes -10 bytes thanks to inspiration from Giuseppe {b=n=1;\()(b<<-c(b,sample(7)))[n<<-n+1]} Attempt This Online! A reuseable function that on ...
Dominic van Essen's user avatar
8 votes

Implement a bag without replacement

JavaScript (ES6), 50 bytes A function that draws one piece at a time. m=f=_=>m^(m|=1<<(i=Math.random()*7))?-~i:f(m%=127) Try it online! Commented ...
Arnauld's user avatar
  • 188k
8 votes

Salacious Bacon Tripod

JavaScript (Node.js), 93 bytes -N bytes thanks to Arnoud and I4m2 ...
mousetail's user avatar
  • 11.8k
8 votes

Output a random value from the last 16 values outputted

Vyxal, 15 13 12 9 bytes k6≬℅+Ḣ↔ƒ⋎ Try it Online! Outputs characters from the string "0123456789abcdef" -3 thanks to ...
lyxal's user avatar
  • 32.5k
8 votes

Output a random value from the last 16 values outputted

R, 66 61 bytes x=Map(show,L<-1:16) while(sd(L))L=c(L[-1],print(sample(L,1))) Try it online! Explanation outline: Map the <...
pajonk's user avatar
  • 15.1k
8 votes

Output a random value from the last 16 values outputted

R, 52 bytes a=b=16:1;while(sd(a[b]))a=c(sample(a[b],1),a);rev(a) Try it online! Full program that yields an R vector containing the sequence of values. R displays ...
Dominic van Essen's user avatar
8 votes

A randomly colored walk

Wolfram Language (Mathematica), 96 bytes (d=#2;r={0,255};NestList[⌊RandomPoint[Sphere[#,d],1,{r,r,r}][[1]]⌋&,RandomInteger[r,3],#1])& Try it online! ...
lesobrod's user avatar
  • 3,239
8 votes
Accepted

Elect the Doge of Venice

05AB1E, 24 bytes •10¢–‘Þ}Ò•46вvNÉiK}.ry£= Print each intermediate result as a list on a separated line to STDOUT. Try it online. Explanation: ...
Kevin Cruijssen's user avatar
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
  • 33k
7 votes

Halt with 50% non-Halting

Random Brainfuck, 5 bytes ?[--] Try it online! Random BF extends BF's set of primitives with the ?, which generates a random ...
AviFS's user avatar
  • 2,111
7 votes

Halt with 50% non-Halting

Lost, 2 bytes %@ Try it online! Although this is apparently a popcon, I figure the language itself is adequately interesting! Lost is a fairly standard toroidal 2D ...
Unrelated String's user avatar
7 votes

Implement a bag without replacement

Raku, 23 bytes {grab $||=SetHash(^7):} Try it online! Ungolfed: { state $bag ||= SetHash(0..6); $bag.grab; } This is a ...
Sean's user avatar
  • 7,906
7 votes

Create a bingo card generator

Vyxal J, 29 bytes (‛₆ṫ⇧Ṅ75ɾ15ẇƛÞ℅5Ẏ;∩2≬2‛λċȦV⁋¶ Try it Online! Explained (old) ...
lyxal's user avatar
  • 32.5k
7 votes

Output a random value from the last 16 values outputted

Brachylog, 18 bytes 15⟦ẉ₂ᵐ{=|ṛRẉ&b,R↰} Try it online! ...
Fatalize's user avatar
  • 38.4k
7 votes

Output a random value from the last 16 values outputted

JavaScript (ES7), 74 bytes Same algorithm as the other version, but using the weirder set "5368709124,false". ...
Arnauld's user avatar
  • 188k
7 votes

Generate an emoticon

Japt -P, 43 bytes "'*;^` -coux $+-Oox~ ,._"¸ò ö mö Vp[VU]ö Îö Saved four thanks to Shaggy Try it or generate 10 ...
noodle man's user avatar
  • 5,262
7 votes

XOR of independent Bernoulli variables

BQN, 8 6 bytesSBCS Based on xnor's Haskell answer, 2 bytes saved by att and BQN's extensions of logical functions to real numbers. (∨-∧)´ Run online! Spells the ...
ovs's user avatar
  • 58k
7 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,647
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
  • 771
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
6 votes

Implement Minceraft

Minecraft, 226 bytes. ...
Tsumiki Miniwa's user avatar
6 votes

Implement a bag without replacement

05AB1E, 9 bytes [7L.r)˜ć, Uses a bag with integers [1,2,3,4,5,6,7]. Outputs the random piece indefinitely on separated newlines....
Kevin Cruijssen's user avatar

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