SHOW:
|
|
- or go back to the newest paste.
| 1 | - | ### RRand.tcl 3.3.0 pQFrdM8L |
| 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 | #Mail: [email protected] | |
| 29 | # | |
| 30 | #Thanks to guys on #egghelp on irc.freenode.net | |
| 31 | ||
| 32 | #PURPOSE | |
| 33 | # With this proc, it'll be simplier randomize | |
| 34 | #a number in an interval between 2 of them | |
| 35 | # of your choice. | |
| 36 | #WARN: This script does not work as normal rand | |
| 37 | # command! Extreme will be incorporated in | |
| 38 | - | #set var [rrand a b] |
| 38 | + | # numbers range. |
| 39 | ||
| 40 | #USAGE | |
| 41 | #set var [rrand a ?b?] | |
| 42 | # a InferiorLimit | |
| 43 | # b SuperiorLimit | |
| 44 | #If b is not setted, it will be assumed as 0 | |
| 45 | ||
| 46 | ||
| 47 | - | error "Inferior Limit is not a number" |
| 47 | + | |
| 48 | ||
| 49 | proc rrand {inf {sup {}}} {
| |
| 50 | - | return [rand $inf] |
| 50 | + | |
| 51 | error "\002$inf\002 Must Be A Number" | |
| 52 | } | |
| 53 | - | error "Superior Limit is not a number" |
| 53 | + | |
| 54 | set sup 0 | |
| 55 | } | |
| 56 | if {![string is integer -strict $sup]} {
| |
| 57 | error "\002$sup\002 Must Be A Number" | |
| 58 | } | |
| 59 | if {$inf == $sup} {
| |
| 60 | return $inf | |
| 61 | } | |
| 62 | if {$inf > $sup} {
| |
| 63 | set infb $inf | |
| 64 | set inf $sup | |
| 65 | set sup $infb | |
| 66 | } | |
| 67 | set gap [expr {$sup - $inf + 1}]
| |
| 68 | return [expr {int(rand() * $gap) + $inf}]
| |
| 69 | } | |
| 70 | ||
| 71 | ### | |
| 72 | putlog "RRand.tcl LOADED" |