Generate rectangle triangle
This commit is contained in:
parent
7ed1780bf6
commit
c6cfab1d44
@ -5,6 +5,7 @@ import jinja2, random, os
|
||||
import sys
|
||||
import optparse
|
||||
from rd_frac import frac
|
||||
from pythagore import pythagore_triplet
|
||||
|
||||
def randfloat(approx = 1, low = 0, up = 10):
|
||||
""" return a random number between low and up with approx floating points """
|
||||
@ -30,6 +31,9 @@ def gaussRandomlist_strInt(mu = 0, sigma = 1, size = 10):
|
||||
random.gaussRandomlist_strInt = gaussRandomlist_strInt
|
||||
|
||||
random.frac = frac
|
||||
random.pythagore = pythagore_triplet
|
||||
|
||||
|
||||
|
||||
|
||||
report_renderer = jinja2.Environment(
|
||||
|
33
pythagore.py
Normal file
33
pythagore.py
Normal file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
from random import randint
|
||||
|
||||
def pythagore_triplet(v_min = 1, v_max = 10):
|
||||
"""Random pythagore triplet generator
|
||||
|
||||
:param v_min: minimum in randint
|
||||
:param v_max: max in randint
|
||||
:returns: (a,b,c) such that a^2 + b^2 = c^2
|
||||
|
||||
"""
|
||||
u = randint(v_min,v_max)
|
||||
v = randint(v_min,v_max)
|
||||
while v == u:
|
||||
v = randint(v_min,v_max)
|
||||
|
||||
u, v = max(u,v), min(u,v)
|
||||
|
||||
return (u**2-v**2 , 2*u*v, u**2 + v**2)
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(pythagore_triplet())
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
Loading…
Reference in New Issue
Block a user