diff --git a/number_rotation.py b/number_rotation.py index a68e663..88498d3 100755 --- a/number_rotation.py +++ b/number_rotation.py @@ -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( diff --git a/pythagore.py b/pythagore.py new file mode 100644 index 0000000..cb11aae --- /dev/null +++ b/pythagore.py @@ -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