DoctorD90

RRand.tcl

Apr 19th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### RRand.tcl 3.3.2 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. #WARN: This script does not work as normal rand
  36. #      command! Extreme will be incorporated in
  37. #      numbers range.
  38.  
  39. #USAGE
  40. #set var [rrand a ?b?]
  41. #  a  InferiorLimit
  42. #  b  SuperiorLimit
  43. #If b is not setted, it will be assumed as 0
  44.  
  45.  
  46. ### DON'T EDIT ANYTHING BELOW ###
  47.  
  48. proc rrand {inf {sup {}}} {
  49.   if {![string is integer -strict $inf]} {
  50.     error "\002$inf\002 Must Be A Number"
  51.   }
  52.   if {![string length $sup]} {
  53.     set sup 0
  54.   }
  55.   if {![string is integer -strict $sup]} {
  56.     error "\002$sup\002 Must Be A Number"
  57.   }
  58.   if {$inf == $sup} {
  59.     return $inf
  60.   }
  61.   if {$inf > $sup} {
  62.     set infb $inf
  63.     set inf $sup
  64.     set sup $infb
  65.   }
  66.   set gap [expr {$sup - $inf + 1}]
  67.   return [expr {int(rand() * $gap) + $inf}]
  68. }
  69.  
  70. ###
  71. putlog "RRand.tcl LOADED"
Advertisement