Personal tools
You are here: Home diverse filer til download mm. Random.py
Document Actions

Random.py

by admin last modified 2007-07-10 09:06

http://www.eksperten.dk/spm/785357

Click here to get the file

Size 1.3 kB - File type text/python-source

File 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() 
Related content
« May 2012 »
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Chat Rooms
CMS ?

Sparer man tid og penge på Plone

ja
nej
ved ikke

Dyrk motion

Trim ballerup

 

Powered by Plone, the Open Source Content Management System