mIRC Home    About    Download    Register    News    Help

Print Thread
#97449 12/09/04 11:05 PM
Joined: Sep 2004
Posts: 2
J
JimpsEd Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
J
Joined: Sep 2004
Posts: 2
Hi there.

Does anyone know why $rand is not Random? And oddly seems to "prefer" border line integers?


Many thanks;

Jamie

#97450 13/09/04 12:19 AM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
In case you're not testing your code on v6.16, it's recommended that you upgrade. I heard that the way $rand() works was changed recently.

#97451 13/09/04 01:41 AM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
As Online says, $rand() is fixed in newer versions (I'm unsure precisely when, versions.txt only mentions changes in v6.1 although I thought I'd seen it still broken since then - perhaps not).

As an example I used this alias
Code:
bmr {
  ; Usage: /bmr <sample-size>
  var %i = $$int($1), %r1 = 0, %r2 = 0, %r3 = 0
  while %i {
    inc $+(%, r, $rand(1,3))
    dec %i
  }
  echo -a $!rand(): 041: %r1 $+ ; 042: %r2 $+ ; 043: %r3 $+ ;
}


Using /bmr 10000 I got:
$rand(): [color:red]1: 3329; 2: 3329; 3: 3342;[/color]
which in a bugged version would have shown 2 to return half as often as 1 or 3.


Spelling mistakes, grammatical errors, and stupid comments are intentional.

Link Copied to Clipboard