Random.py
by
admin
—
last modified
2007-07-10 09:06
http://www.eksperten.dk/spm/785357
Size 1.3 kB - File type text/python-sourceFile contents
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import random
Page = """Content-type: text/html
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Se og hent kildekoden <a target="_blank" href="http://www.databassen.dk:8090/bauerdata/python-program-eksempler/Random.py">her</a>
<hr>
<p><a href="Random.py">Ny liste</a></p>
<hr>
<table border="1"><td>%(liste)s</td></table>
<hr>
<b>Python er nemt, Python er sjovt.</b>
</html>
"""
from pprint import pprint
def Random( minDiff=5, maxDiff=12 , Min=1, Max=29, Repeats=60, Sort=False ):
assert 0 < minDiff < maxDiff < Max
assert 0 < Min < Max
assert Min + minDiff * 2 < Max
assert 0 < Repeats
Set = range( Min, Max + 1 )
Liste = []
while len( Liste ) < Repeats:
Tal = [ random.choice(Set) for i in range( 3 ) ]
Tal.sort()
(A1,A2,A3) = Tal
highDif = A3 - A2
lowDif = A2 - A1
if not minDiff <= highDif <= maxDiff: continue
if not minDiff <= lowDif <= maxDiff: continue
if highDif == lowDif: continue
if Liste.count(Tal) == 0:
Liste.append( Tal )
if Sort:
Liste.sort()
return Liste
liste = "</td><td>".join( [ "%s %s %s" % ( y[0] , y[1], y[2] ) for y in Random() ] )
print Page % vars()
Click here to get the file