Radio Shack TRS-80 User Manual page 103

Micro computer system
Hide thumbs Also See for TRS-80:
Table of Contents

Advertisement

The
Old Coin
Toss Gambit.
Remember
now, you
could
toss
a
thousand heads
in
a
row
and
the
odds on
the
next
toss
are exactly
50/50
that
a
head
will
come up
again.
Every
toss
is
totally
independent of
what
happened
before
it,
IT
IS TOO!!!!!
In
the
long run however, the
number
of
heads
and
tails
should be
exactly the
same.
{Casinos
live
off
people
who
go broke
waiting
for their particu-
lar
scheme
to
pay
off
.
.
.
"in
the long run").
Your Computer
will
give
you
a
complete
edu-
cation
in
"odds" and
various
games
of chance,
and
allow
you
to
prove or disprove
many
ideas involving probability. This
is
known
as
computer "modeling"
or "simulation."
We're
going
to write
this
coin
toss
simulation
program
in
Radio Shack Shorthand and
use
multiple statement
lines just
for
the
practice.
Type
it
in
very
carefully to
avoid
errors:
10
H=0tT=0:P.
20
IN.
"HOW
MANY TIMES SHALL WE FLIP THE
COIN";F:CLS
30
P.
"YOU STAND
BY
WHILE
I
DO THE
FLIPPING
------
40
F.N=1T0F:X=RND(2
)
jONXG.
60,70
50
P.
"IT BOMBED! WAS NEITHER
A
1
NOR
A
2
.
"
\
END
60 H=H+1
sG.
80
70 T=T+1
80 N,N
jP. :P
.
sP
.
iP.
90
P.
"HEADS
TAILS
TOTAL
FLIPS'
P.
tP.H.T.F
100
P.
100*H/F;
"
%
"
,
100*T/F
s
:P. :P,
.
.
.
and
RUN.
"Flip the coin"
100
times
on
the
first
RUN
to
get a
feel
for
the
program and
the run
time.
RUN
as
many
times
as
it
takes to
convince
you
that
the
random number
generator produces
really
random
numbers.
When
it's
time
for
lunch or
you
can wait
quite
awhile
for
the answer,
try
25,000
flips
or
more.
Program
analysis:
Line
10
contains 3 statements.
The
first
initializes
H
(for
Heads)
at zero.
The
second
sets
T
(for Tails)
equal
to
zero.
The
third
inserts
a space
in
the printout
with
a
PRINT(P.).
Line 20
has 2 statements.
1
Inputs the
number
of
flips
desired.
2
A
clear
screen
(CLS)
to
start
the
next
print
line
at
the
top
of the
screen.
Line 30
Prints a
"Standby"
statement.
Line 40
has 3 statements.
1
Begins a
FOR-NEXT
loop
that
runs
"F"
times.
2
Is
"VOU IOSH"
101

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents