mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 2 1 2
#43527 23/08/03 03:42 PM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
Code:

;  Usage: $randrange(<lower>,<upper>,[exclude range][,...])
;
alias randrange {
  var %tries = 1, %maxtries = 100, %found = $false, %2 = $2 + 1, %r = $rand($1, %2)
  if (%r == %2) %r = $1
  while (!%found) {
    %found = $true
    if !$3 { break }
    var %i = 1
    while $gettok($3-, %i, 32) != $null { 
      if %r isnum $ifmatch {
        var %found = $false, %i = $numtok($3-, 32), %r = $rand($1, %2)
        if (%r == %2) %r = $1
      }
      inc %i
    }
    inc %tries
    if (%tries == %maxtries) return
  }
  return %r
}

//echo -a * $randrange(1,200, 10-25, 60-75, 110-125, 160-175)

* 97
* 87
* 42
* 33
* 190

EDIT:
  1. Fixed upper bound bug when the lower bound was excluded.
  2. Added MaxTries to prevent infinite loops if all valid values
    end up excluded. Now returns $null if unsuccessful.

Last edited by Hammer; 24/08/03 12:17 PM.

DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#43528 24/08/03 01:01 AM
Joined: Dec 2002
Posts: 196
T
Vogon poet
OP Offline
Vogon poet
T
Joined: Dec 2002
Posts: 196
Well, in the case of ZZ and zz, it will return any letter from ZZ to zz.

Like ZZ, aa, ab, ac ...... zz


trenzterra
AustNet #trenzterra and #w
Head Scripter @ http://trenzterra.uni.cc
#43529 24/08/03 11:45 AM
Joined: Feb 2003
Posts: 143
N
Vogon poet
Offline
Vogon poet
N
Joined: Feb 2003
Posts: 143
there is a bug in that script I've seen. I did $randrange(1,10, 1-5) and it returns 1 everynow and then

[07:42] <naki[afk]> $randrange(1,10 ,1,5)
[07:42] <naki[afk]> 1
[07:42] <naki[afk]> 1
[07:42] <naki[afk]> 10
[07:42] <naki[afk]> 6
[07:42] <naki[afk]> 7
[07:42] <naki[afk]> 6
[07:42] <naki[afk]> 6
[07:42] <naki[afk]> 1


We don't just write the scripts, we put them to the test! (ScriptBusters)
Page 2 of 2 1 2

Link Copied to Clipboard