# Random Binary Decision

### By Sardukar2 on Apr 07, 2006

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.*

}
``````

LIQUID_NiTrO   -  Apr 15, 2006

I\'m no expert on this so tell me if I\'m wrong, but couldn\'t you theoretically create an md5 hash that contained no numbers?

bl4h   -  Apr 08, 2006

but \$rand(1,1) will have the same 50/50 results

you say

I tested this random binary generator 100000 times, and the results are:
%j.countgreaterequaltofive 49632
%j.countlessthan5 50367

try that with \$rand(1,2)

same results i bet

QuickStep   -  Apr 07, 2006

I don\'t see why this is more usefull than e.g. \$rand(0,1) .. The idea is nice though

Sardukar2   -  Apr 07, 2006

Note, as with anything ever created by man - this is not 100% random and not 100% unbiased. However, for the purposes of ANYTHING you may want to do in mIRC script, this is more than random and more than unbiased for one\'s needs.

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.