7 lines
296 B
Mathematica
7 lines
296 B
Mathematica
n = 20; % number of coin flips
|
|
P = 0.6; % probability of head
|
|
u = rand(n, 1); % n random numbers between 0 and 1
|
|
heads = u < P; % true if head showed up
|
|
nheads = sum(heads); % number of heads
|
|
fprintf('Of %d coin flips, %d heads showed up.\n', n, nheads);
|