# [Tutor] Random module.. or? CORRECTION

bhaaluu bhaaluu at gmail.com
Tue Aug 7 23:16:32 CEST 2007

```Greetings,

I just had to play with Bob's probabilities...
The standard disclaimer applies: This Python
source code has been written by a Noob, so
use it at your own risk. =)

#!/usr/bin/env python
# randy.py
# 2007-08-07
# b h a a l u u at g m a i l dot c o m
import random

def randy():
a=[]
for i in range(1,10001):
a.append(i)
#print a[0]
#print a[9999]
b = random.choice(a)
print b
if b <= 1:
print "45 points scored!"
elif b > 1 and b <= 11:
print "30 points scored!"
else:
c=[]
for i in range(26):
c.append(i)
d = random.choice(c)
print d,"points scored!"

randy()

--
bhaaluu at gmail dot com

On 8/7/07, Bob Gailer <bgailer at alum.rpi.edu> wrote:
> Bob Gailer wrote:
> > Tony Noyeaux wrote:
> >
> >> As always, thanks all for the ongoing help and suggestions... the
> >> learning continues.
> >>
> >> I've successfully made a number of programs, making use of various
> >> random code.
> >>
> >> Using random.choice etc
> >> #-----------------------------------
> >> import random
> >> letters = ('a', 'b', 'c', 'd')
> >> a = random.choice(letters)
> >> print 'your random letter is %s' %(a)
> >> #------------------------------------
> >> or
> >> #------------------------------------
> >> import random
> >> letters = ('a', 'a', 'b', 'b', 'c', 'd')
> >> a = random.choice(letters)
> >> print 'your random letter is %s' %(a)
> >> #-----------------------------------
> >>
> >> In the first random... , each abcd, has a equal chance of coming out.
> >> In the 2nd random,... a b,.. have an extra chance vs c/d to come out,
> >> making them more likely.
> >>
> >> What i would like to experiment now with is,...
> >>
> >> How can you control randomness... lets say for fish.
> >>
> >> CatfishBreedA
> >> Can be say, 4inches, to 24inches long
> >> Most fish caught are say 7-14inches long
> >> Maybe 1 in 1000 catfish caught are say, 16-20 inches long
> >> Maybe 1 in 10000 catfish caught are say, 20inches +
> >>
> >> How.. can you program that kind of randomness?
> >>
> >> Or another way to look at it.
> >>
> >> Can score 4-45pts a game.
> >> Most games, he scores 15-25 pts
> >> Maybe 1 in 1000 games he scores 30 plus pts
> >> Maybe 1 in 10000 he scores 45 pts.
> >>
> >> The actual %'s, lengths, and pts are irrelevent,.. they are just used
> >> to as an example.
> >>
> >>
> >> Any guidance would be appreciated.
> >>
> > 10000 games would  be distributed thus:
> >     1 = 45 pts
> >    10 = 30+ pts
> >  9989 = 15-25 pts CORRECTED
> > so generate a random integer between 1 and 10000.
> > if it is <= 1 then 45
> > else if it is <= 11 then 30+
> > else 15-25
> >
> > Enough to get you going?
> >
> >
>
>
> --
> Bob Gailer
> 510-978-4454 Oakland, CA
> 919-636-4239 Chapel Hill, NC
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>

--
bhaaluu at gmail dot com
```