mIRC Home    About    Download    Register    News    Help

Print Thread
$rand bug? #4999 05/01/03 04:36 AM
Joined: Jan 2003
Posts: 2
D
dragonslayer Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
D
Joined: Jan 2003
Posts: 2
hi,

don't know if this can be fixed but I did a test on the $rand identifier and it seems to pick the first and last number only half of the time compared to the others... can this be fixed somehow or can I get around it?

Re: $rand bug? #5000 05/01/03 06:38 PM
Joined: Dec 2002
Posts: 2,809
C
codemastr Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
There is no such thing as a "random number" A computer uses a PRNG (pseudo random number generator) to try and create random numbers. But computers do not understand the concept of randomness, all the random numbers are predictable if you know the formula to use. The only real way to fix this is to use a better PRNG, people have suggested others that are better, but Khaled has never actually used them, so I doubt he will change his mind now...

Re: $rand bug? #5001 06/01/03 09:02 PM
Joined: Dec 2002
Posts: 2,985
Watchdog Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 2,985
That might be an issue but is it such a bad thing? Randomness does not mean that each number should be drawn out of the hat the same number of times. As codemastr stated, computers don't know about randomness. They can't really because they don't know how long you are going to draw random numbers for. Therefore the likelyhood of all numbers getting drawn the same number of times is very slim indeed.

Re: $rand bug? #5002 06/01/03 10:20 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Actually that is the exact point - over a large enough scale all numbers should come out around the same number of times. Of course, in general when it comes to mIRC scripting the randomness of $rand() is perfectly acceptable (perhaps when using only 3-6 random characters it might be noticeable).


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: $rand bug? #5003 07/01/03 04:24 PM
Joined: Jan 2003
Posts: 2
D
dragonslayer Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
D
Joined: Jan 2003
Posts: 2
Well it's just annoying that when I use $rand(1,3) it returns 2 half of the time. I know computers have a hard time generating random numbers, but I didn't know mIRC's algorithm is so messed up. Another weird thing is that this 'bug' doesn't occur when using letters instead of numbers.

Re: $rand bug? #5004 07/01/03 10:17 PM
Joined: Dec 2002
Posts: 1,321
H
Hammer Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
To test this and see if the allegations are true, I wrote this alias to run a series of 100,000 random runs:
Code:

alias rand.count {
  var %1, %2, %3, %4, %5
  var %i = 1
  while (%i < 100000) {
    inc $+(%,$r(1,5))
    inc %i
  }
  echo -ati2 ** 1( $+ %1 $+ ) 2( $+ %2 $+ ) 3( $+ %3 $+ ) 4( $+ %4 $+ ) 5( $+ %5 $+ )
}

Here are the results of several runs of this alias.

** 1(12458) 2(24842) 3(25015) 4(25157) 5(12527)
** 1(12876) 2(24764) 3(25271) 4(24720) 5(12368)
** 1(12422) 2(25034) 3(25186) 4(24885) 5(12472)
** 1(12600) 2(24789) 3(25104) 4(25070) 5(12436)
** 1(12632) 2(25110) 3(24968) 4(25071) 5(12218)
** 1(12517) 2(25157) 3(25078) 4(24769) 5(12478)
** 1(12599) 2(25137) 3(24835) 4(24956) 5(12472)
** 1(12457) 2(25135) 3(25054) 4(24914) 5(12439)
** 1(12666) 2(25126) 3(25196) 4(24663) 5(12348)
** 1(12630) 2(25098) 3(24893) 4(24997) 5(12381)

From this, we can determine that the first and last DO show up half the number of times as the others. 2-4 are quite evenly distributed. That means that if you wanted to derive a "more truly random number", take $rand(1-(N-1), counting N as a 1. So if I need a random number from 1 to 3, I can use something $rr(1,3) - like this:
Code:

alias rr {
  var %n = $rand($1,$calc($2 + 1))
  if (%n == $calc($2 + 1)) return $1
  return %n
)

Substituting $rr for $r in the above alias uses the new RealRand alias and returns the following:

** 1(19939) 2(19977) 3(19938) 4(20143) 5(20002)
** 1(19971) 2(19956) 3(20202) 4(20162) 5(19708)
** 1(19813) 2(20021) 3(20046) 4(19967) 5(20152)
** 1(20190) 2(20199) 3(19999) 4(19823) 5(19788)
** 1(19808) 2(20136) 3(19971) 4(19991) 5(20093)
** 1(20027) 2(20198) 3(19994) 4(19891) 5(19889)
** 1(19928) 2(19954) 3(20049) 4(20106) 5(19962)
** 1(20020) 2(20014) 3(20107) 4(19976) 5(19882)
** 1(19998) 2(20161) 3(19927) 4(19971) 5(19942)
** 1(20078) 2(19899) 3(19991) 4(20139) 5(19892)


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Re: $rand bug? #5005 20/01/03 01:35 PM
Joined: Dec 2002
Posts: 25
S
SubSpace Offline
Ameglian cow
Offline
Ameglian cow
S
Joined: Dec 2002
Posts: 25
Hmm, I just posted about this myself and only found this thread now (sorry blush)

The thing is that this effect was not present in 6.0 and 6.01, so I would consider it a bug and not a result of computers being unable to produce random numbers.

The formula in the $rand function was changed and it was broken... Change it back please smile

Re: $rand bug? #5006 21/01/03 10:27 AM
Joined: Dec 2002
Posts: 191
N
Nobodi Offline
Vogon poet
Offline
Vogon poet
N
Joined: Dec 2002
Posts: 191
the bug is/was also present in 5.91

Re: $rand bug? #5007 28/04/04 04:36 AM
Joined: Apr 2003
Posts: 426
neophyte Offline
Fjord artisan
Offline
Fjord artisan
Joined: Apr 2003
Posts: 426
As has been pointed out before, computer generated random numbers are not random.

The only way to be as close to random as possible, would be to use some sort of equation that took the input of radio wave noise from stars, and turned it into a number, yet that itself would still be a somewhat 'psuedo' generated number.


--------
mIRC - fun for all the family (except grandma and grandpa)