This script has been designed for scripts that need to make a decision out of two options.
The script will generate a random integer in mIRC (which alone is usually biased, in some peoples opinions (do not discuss this here please), and performs an MD5 hash on it.
MD5 hash will be made of 32 characters, a mix of numbers and alphas.
The script will go through the hash until it gets to a number. Then, it checks if the number is less than 5 (0,1,3,4). If it is, it will return 1. If it is greater than 5 (6,7,8,9), it will return 0.
Example usage:
if ( $randmd5 == 1 ) {
do_this
}
else {
do_thisother
}
I tested this random binary generator 100000 times, and the results are:
%j.countgreaterequaltofive 49632
%j.countlessthan5 50367
Enjoy :-)
alias randmd5 {
set %t.randomhash $md5($rand(100000,99999999))
set %i 1
while ( %i <= 32 ) {
if ( $mid(%t.randomhash,%i,1) isnum ) {
if ( $mid(%t.randomhash,%i,1) < 5 ) {
return $null
}
else if ( $mid(%t.randomhash,%i,1) > 5 ) {
return 1
}
}
inc %i
}
unset %i
unset %t.*
}