mIRC Home    About    Download    Register    News    Help

Print Thread
mIRC 6.03 $rand bug #7516 20/01/03 01:25 PM
Joined: Dec 2002
Posts: 25
S
SubSpace Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Dec 2002
Posts: 25
Hi,

There's a bug in mIRC 6.03 regarding the $rand function that is not present in 6.0 and 6.01. When I do $rand(1, 20) for example, the number of 1's and 20's that show up is only half to 2-19.

I told some other people about it and they can't reproduce the error under the two earlier mentioned versions, but they get the same result as me under 6.03

Example output of the script I ran, changed to $rand(1,3) for brevity:

10000 iterations performed
-----------------------
1: 2521 occurences (25.21 percent)
2: 4999 occurences (49.99 percent)
3: 2480 occurences (24.8 percent)

Here's the script itself:

Code:
/probtest {
  var %max = 3

  var %i = 1
  while (%i < $1) {
    var %prob_ [ $+ [ %i ] ]
    inc %i
  }

  %i = 0
  while (%i < $1) {
    inc %prob_ [ $+ [ $rand(1, %max) ] ]
    inc %i
  }

  echo 2 $1 iterations performed
  echo 2 -----------------------

  %i = 1
  var %nr
  while (%i <= %max) {
    %nr = [ %prob_ [ $+ [ %i ] ] ]
    echo 2 %i $+ : %nr occurences ( $+ $calc(%nr / $1 * 100) percent)
    inc %i
  }
}


I solved it temporarely by using the following alias instead:

Code:
/dice_rand {
  if ($0 < 2) return
  var %result
  while (!%result || %result < $1 || %result > $2) {
    %result = $rand($calc($1 - 1) , $calc($2 + 1))
  }
  return %result
}


However I suggest you change the $rand command to what it was smile

Re: mIRC 6.03 $rand bug #7517 20/01/03 09:16 PM
Joined: Dec 2002
Posts: 39
F
fraggle Offline
Ameglian cow
Offline
Ameglian cow
F
Joined: Dec 2002
Posts: 39
eeeeeeek

this beast is back?

it was fixed back in 5.61 or something :P

A quicker solution, and a more generic one would be something along the lines of

Code:
  
/myrand {
var %randvar = $rand($1,$calc($2 + 1))
if ( %randvar == $calc($2 + 1) ) return $1
return %randvar
}

(NOTE: not sufficiently tested, but it should work)

but it wouldnt work with $myrand(a,z) like $rand does

Re: mIRC 6.03 $rand bug #7518 21/01/03 02:47 AM
Joined: Dec 2002
Posts: 25
S
SubSpace Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Dec 2002
Posts: 25
Indeed the script is quicker, but it has a side effect which made me choose the other approach: if the bug is ever fixed, you have an increased chance for 'a'.

It's not more general, both of them do effectively the same under practically all circumstances.

Re: mIRC 6.03 $rand bug #7519 21/01/03 03:41 AM
Joined: Dec 2002
Posts: 1,321
H
Hammer Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
$chr($myrand(97,122))


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Re: mIRC 6.03 $rand bug #7520 22/01/03 06:26 AM
Joined: Jan 2003
Posts: 24
C
Codeq Offline
Ameglian cow
Offline
Ameglian cow
C
Joined: Jan 2003
Posts: 24
why are u runnin your probe script with 2 while loop which count to outerspace?
btw.. its not an iteration, its just a simple statistic nothin more.

sure a while loop need iteration to run, but thats a different story of address calculation.
so how about this one? runnin on a 3num test by 10000 test 44times faster.
Code:
alias probtest {
  var %time = $ticks
  var %max = 3
  var %i = 1
  while (%i <= %max) {
    var %prob_ [ $+ [ %i ] ] 0
    inc %i
  }
  %i = 0
  while (%i < $1) {
    inc %prob_ [ $+ [ $rand(1, %max) ] ]
    inc %i
  }
  echo 12 $1 iterations performed
  echo 12 -----------------------
  %i = 1
  while (%i <= %max) {
    var %nr = %prob_ [ $+ [ %i ] ]
    echo 12 %i $+ : %nr occurences ( $+ $calc(%nr / $1 * 100) percent)
    inc %i
  }
  echo 12 $calc($ticks - %time) $+ ms elapsed.
}   


and i use thisone to generate my random values... the numbers within one span only return once per cycle. i need that type of behaviour more often than a random int which can be the same number several times one after another.

only limitation is the max length of around 900chrs for a string within mirc for the output.

Code:
;
; radom integer
;
;nimmt per zufall eine Zahl aus %start bis %ende, wobei keine Zahl innerhalb
; eines Durchlaufs zwei mal auftaucht. Es dürfen alles nur Integer werte sein!
;
;
;Version: 1.0.2 - 14.06.2002 by Codeq
;Version: 1.0.4 - 15.06.2002 by Codeq
;Version: 2.0.0 - 09.09.2002 by Codeq
;
;
;
;Sytax: $randomint(<start> <ende> [p]<N>)
;wobei N angibt wie viele zahlen zurückgegeben werden sollen. Bei pN ist es ein Prozentwert.
;
;DONT MAKE CHANGES BELOW THIS LINE
;---------------------------------

alias randomint {
  tokenize 32 $1-
  var %randomint.start = $round($1,0)
  var %randomint.ende = $round($2,0)
  if (%randomint.start < %randomint.ende) {
    if (p == $left($3,1)) { var %randomint.prozent = $remove($3,p) }
    else { var %randomint.absolut = $round($3,0) }
    if (%randomint.start <= %randomint.ende) {
      var %randomint.i = 1
      var %randomint.j = $calc($abs($calc((%randomint.ende * -1) + %randomint.start)) + 1)
      if (%randomint.prozent) { var %randomint.absolut = $round($calc(($remove($3,p) * %randomint.j) / 100),0) }
      if (%randomint.absolut > 0) {
        var %randomint.string 
        var %randomint.output 
        while (%randomint.i <= %randomint.j) {
          var %randomint.string $addtok(%randomint.string,$calc(%randomint.start + %randomint.i - 1),44)
          inc %randomint.i
        }
        while (%randomint.absolut > 0) {
          var %randomint.rand = $rand(1,$numtok(%randomint.string,44))
          var %randomint.output = $addtok(%randomint.output,$gettok(%randomint.string,%randomint.rand,44),44)
          var %randomint.string = $deltok(%randomint.string,%randomint.rand,44)
          dec %randomint.absolut
        }
        return %randomint.output
      }
      else { return *** error: ausgabe muss grösser null sein. }
    }
  }
  else { return *** error: start muss kleiner ende sein. }
}


--
Codeq (J. Diel)
euIRCnet LocOp (irc.hes.de.euirc.net)
http://coding-board.de | www.euirc.net
Re: mIRC 6.03 $rand bug #7521 24/01/03 06:28 PM
Joined: Dec 2002
Posts: 25
S
SubSpace Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Dec 2002
Posts: 25
My bad, of course the first loop condition was supposed to read (%i < %max) and not (%i < $1), which is pretty much all you changed cool

As for the terminology, a single execution of a loop is usually called an iteration, so it's not technically incorrect, even though I agree it's maybe somewhat oddly chosen. Not my choice of words, I modified someone else's script to slightly increase it elegance.. within the limitations of mIRC scripting.

As for your alternative random script: it's not really what I'm looking for. I need it to be truely random, that includes two consecutive identical results. However, it has it's purposes smile

Last edited by SubSpace; 24/01/03 06:37 PM.