31 votes

What an Odd Function

Jelly, 7 bytes Æf^<¥4P Swaps 2s and 3s in the input's prime factorization. The probability of odds is 2/3. Try it online! How it works ...
Dennis's user avatar
  • 210k
29 votes
Accepted

Choose The Powerball Numbers!

Dyalog APL, 10 bytes (5?69),?26 Dyadic ? is ⍺ distinct random numbers in [1,⍵], and monadic ...
lirtosiast's user avatar
  • 21.4k
27 votes

1/N probability

MediaWiki templates with ParserFunctions, 48 bytes {{#ifexpr:1>{{#time:U}} mod {{{n}}}|true|false}}
DuhHello's user avatar
  • 499
26 votes
Accepted

Pick a random number between 0 and n using a constant source of randomness

x86 machines with rdrand instruction, 10 bytes ...
Margaret Bloom's user avatar
21 votes

Pick a random number between 0 and n using a constant source of randomness

Jelly, 7 6 bytes ⁴!!X%‘ Thanks to @JonathanAllan for golfing off 1 byte! Cannot be run on TIO because (16!)! is a huge number. How it works ...
Dennis's user avatar
  • 210k
16 votes

Plot the Gaussian Distribution in 3D

C++, 3477 3344 bytes Byte count does not include the unnecessary newlines. MD XF golfed off 133 bytes. There's no way C++ can compete for this, but I thought it would be fun to write a software ...
Patrick Purcell's user avatar
15 votes

1/N probability

Pyth, 3 bytes !OQ Try it online Simple inversion of random choice from 0 to input Amusingly in Pyth it is not possible to make a function that does this ...
FryAmTheEggman's user avatar
15 votes

Sample a random non-decreasing sequence

Python, 89 bytes from random import* lambda n,k:[x-i for i,x in enumerate(sorted(sample(range(1,n+k),k)))] Generating an increasing sequence rather than a non-...
xnor's user avatar
  • 144k
15 votes

What an Odd Function

Husk, 11 10 bytes -1 byte thanks to Leo, and a slightly different function This has an odd probability of 1 !uΣz:NCNİ1 Try ...
H.PWiz's user avatar
  • 11.6k
13 votes

Choose The Powerball Numbers!

CJam, 16 bytes 69,mr5<26mr+:)S* ...
Doorknob's user avatar
  • 71.4k
12 votes

"i" have "i" chance of occuring

CJam, 14 bytes E,_T9t\]ze~es= Test it here. Explanation ...
Martin Ender's user avatar
12 votes

1/N probability

CJam, 5 bytes Gotta be quick with these ones... rimr! Test it here. Explanation ...
Martin Ender's user avatar
12 votes

1/N probability

TI-BASIC, 4 bytes using one byte tokens not(int(Ansrand Determines if the integer part of the input times a random number in [0,1) is zero. ...
lirtosiast's user avatar
  • 21.4k
12 votes

Pick a random number between 0 and n using a constant source of randomness

Mathematica, 29 bytes Based on Dennis's Jelly answer. RandomInteger[2*^9!-1]~Mod~#& I wouldn't recommend actually running this. ...
Martin Ender's user avatar
11 votes

1/N probability

MATL, 5 bytes Three different versions of this one, all length 5. iYr1= which takes an input (i), generates a random integer ...
David's user avatar
  • 1,316
11 votes

Compute the histogram entropy estimation of a string

Python 3.3+, 64 bytes import math lambda s:sum(math.log2(len(s)/s.count(c))for c in s) Got math.log2 from mbomb007's solution.
xnor's user avatar
  • 144k
11 votes
Accepted

Estimate the mean minimum Hamming distance

Python 3, score = big(?) ...
Anders Kaseorg's user avatar
10 votes

1/N probability

Julia, 17 16 15 bytes n->2>rand(1:n) This is a function that generates a random integer between 1 and n and tests ...
Alex A.'s user avatar
  • 24.6k
10 votes

1/N probability

JavaScript ES6, 15 bytes -5 bytes thanks to Downgoat. x=>1>new Date%x Based off (uses) of this answer's technique.
Conor O'Brien's user avatar
10 votes

Plot the Gaussian Distribution in 3D

Mathematica, 47 bytes Plot3D[E^(-(x^2+y^2)/2/#^2),{x,-6,6},{y,-6,6}]& takes as input σ Input [2] output -2 bytes thanks to LLlAMnYP
ZaMoC's user avatar
  • 24.4k
10 votes

Frequency Distribution of Multiple Dice Rolls

Octave, 38 bytes @(a,b)round(ifft(fft((a:a*b<a+b)).^a)) Try it online! Explanation Adding independent random variables corresponds to convolving their ...
Luis Mendo's user avatar
  • 104k
10 votes

Calculate the probability of getting to the target first (exactly)

Wolfram Language (Mathematica), 25 bytes $$n! \div \left( \sum ^n _{k=0} k!(n-k)! \right)$$ #!/Sum[k!(#-k)!,{k,0,#}]& Try it online! -4 bytes from @ovs
ZaMoC's user avatar
  • 24.4k
10 votes
Accepted

Weighted coin flip strings

05AB1E, 40 39 18 17 bytes Brute-force approach: 0Lα1ݲãʒγOà³@}èPO Byte-count more than halved by porting @JonathanAllan's Jelly answer, which uses a similar ...
Kevin Cruijssen's user avatar
9 votes

1/N probability

Microscript II, 3 bytes NR! Reads an integer n, generates a random integer between 0 and <...
SuperJedi224's user avatar
  • 11.9k
9 votes

Choose The Powerball Numbers!

MATL, 10 bytes 69 5Zr26Yr Uses current version (9.2.0) of the language/compiler. Example With compiler run on Matlab: ...
Luis Mendo's user avatar
  • 104k
9 votes

Probability of something happening at least n out of m times

Mathematica, 29 bytes BetaRegularized[#3,#,1+#2-#]& Takes input in the order n,m,p. Mathematica is so good, it even golfs ...
Sp3000's user avatar
  • 61.7k
9 votes

Pick a random number between 0 and n using a constant source of randomness

Brachylog, 9 bytes ≥.∧13ḟṙ|↰ Try it online! This uses 13! like in Martin Ender's answer (13ḟ...
Fatalize's user avatar
  • 38.4k
9 votes

Hand patterns in a card game

APL (Dyalog Unicode), 30 chars ×/!⍨,z,1÷((z←!∘≢⊢)⌸⊢),×∘≢!⍨1⊥⊢ Try it online! Using @orlp’s formula.
FrownyFrog's user avatar
  • 3,722
9 votes

Probabilistic approach puzzle

Wolfram Language (Mathematica), 33 bytes Uses Binomial and outputs ,really fast, fractions Tr@Binomial[#,Prime@Range@#]/2^#& Try it online! The ...
ZaMoC's user avatar
  • 24.4k
9 votes

Probabilistically fair prize splitting for two-player coin toss

R, 36 32 bytes function(X,A,B)pbeta(.5,X-A,X-B) Try it online! The closed formula from this answer suggested a natural probability distribution to use -- this ...
Giuseppe's user avatar
  • 28.1k

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