DoctorD90

RRand.tcl 3.3.0

Apr 19th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 1.75 KB | None | 0 0
  1. ### RRand.tcl 3.3.0 pQFrdM8L
  2.  
  3. #REQUIREMENTS
  4. # PBinScr.tcl fMrtKqyq
  5.  
  6. #LICENSE
  7. # Copyright © 2013 Alberto Dietze "DoctorD90"
  8. #
  9. #    This program is free software: you can redistribute it and/or modify
  10. #    it under the terms of the GNU General Public License as published by
  11. #    the Free Software Foundation, either version 3 of the License, or
  12. #    (at your option) any later version.
  13. #
  14. #    This program is distributed in the hope that it will be useful,
  15. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. #    GNU General Public License for more details.
  18. #
  19. #    You should have received a copy of the GNU General Public License
  20. #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. # Full GPLv3 Text: http://www.gnu.org/licenses/gpl.txt
  23.  
  24. #PATERNITY
  25. #Coder: DoctorD90
  26. #Network: irc.OnlineGamesNet.net
  27. #Chan: #eHito
  28. #
  29. #Thanks to guys on #egghelp on irc.freenode.net
  30.  
  31. #PURPOSE
  32. # With this proc, it'll be simplier randomize
  33. #a number in an interval between 2 of them
  34. # of your choice.
  35.  
  36. #USAGE
  37. #set var [rrand a b]
  38. #  a  InferiorLimit
  39. #  b  SuperiorLimit
  40.  
  41.  
  42. ### DON'T EDIT ANYTHING BELOW ###
  43.  
  44. proc rrand {inf {sup {}}} {
  45.   if {![string is integer -strict $inf]} {
  46.     error "Inferior Limit is not a number"
  47.   }
  48.   if {![string length $sup]} {
  49.     return [rand $inf]
  50.   }
  51.   if {![string is integer -strict $sup]} {
  52.     error "Superior Limit is not a number"
  53.   }
  54.   if {$inf == $sup} {
  55.     return $inf
  56.   }
  57.   if {$inf > $sup} {
  58.     set infb $inf
  59.     set inf $sup
  60.     set sup $infb
  61.   }
  62.   set gap [expr {$sup - $inf + 1}]
  63.   return [expr {int(rand() * $gap) + $inf}]
  64. }
  65.  
  66. ###
  67. putlog "RRand.tcl LOADED"
Advertisement
Add Comment
Please, Sign In to add comment