Share Pastebin
Guest
Public paste!

fduppafduppacomar

By: a guest | Apr 29th, 2009 | Syntax: Python | Size: 1.61 KB | Hits: 407 | Expires: Never
Copy text to clipboard
  1. #!/usr/local/bin/python3.0
  2.  
  3. #   Copyright (C) 2009 Federico Sebastian De Malmayne Duppa
  4.  
  5. #   This program is free software: you can redistribute it and/or modify
  6. #   it under the terms of the GNU General Public License as published by
  7. #   the Free Software Foundation, either version 3 of the License, or
  8. #   (at your option) any later version.
  9.  
  10. #   This program is distributed in the hope that it will be useful,
  11. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #   GNU General Public License for more details.
  14.  
  15. #   You should have received a copy of the GNU General Public License
  16. #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  
  18. #    This program generates a random number between specified limits
  19.  
  20. import random
  21.  
  22. #   Edit these variables accordingly
  23. #   amount = How many numbers are generated
  24. #   floor = minimum value
  25. #   roof = maximum value
  26. #
  27. #   default values (eg Quini 6) amount = 6; floor = 0; roof = 45;
  28. amount = 6
  29. floor = 0
  30. roof = 45
  31. #    End of editable space
  32.  
  33. while True:
  34. #   cleans control flag & throws away any leftovers in the list
  35.     li = []
  36.     control = 0
  37. #   appends elements to the list
  38.     for i in range (1, amount + 1):
  39.         aleatorio = random.randrange(floor, roof + 1)
  40.         li.append(aleatorio)
  41. #   check if there are repeated elements
  42.     for i in range (0, amount):
  43.         if li.count(li[i]) != 1:
  44.             control = control + 1
  45.             break
  46. #   if no repeated elemets, break the while
  47.     if control == 0:
  48.         break
  49.  
  50. li.sort()
  51.  
  52. print(li)