mIRC Home    About    Download    Register    News    Help

Print Thread
$read()'s random function is not uniform #245640 30/04/14 12:12 PM
Joined: Jul 2006
Posts: 3,584
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,584
Code:
alias test_read {
  var %a 1,%b $iif($1 isnum 4- && . !isin $1,$1,3),%r
  .fopen -no test test
  if ($ferr) { echo -s * test_read ferr at opening | return }
  else {
    while (%a <= %b) {
      .fwrite -n test %a
      if ($ferr) { echo -s * test_read ferr at writting | return }
      inc %a
    }
    .fclose test
    %a = $iif($2 isnum 4- && . !isin $2,$2,100000)
    while (%a) {
      inc %testread $+ $read(test,tn)
      dec %a 
    }
    ;grab all variables created and display their value
    %a = 1
    while ($var(testread*,%a)) {
      %r = %r $+($remove($v1,%,testread),:,$var(testread*,%a).value)
      inc %a
    }
    unset %testread*
    echo -a * test_read $sorttok(%r,32,n)
  }
}
Usage: /testread [lines] [iterations]
[lines] default to 3, [iterations] default to 100000
The alias creates a file "test" in the mircdir with [lines] lines in it, the value of each line is its own line number, after that it loops [iterations] times, calling $read(test,tn) and increasing a dynamic variable (the dynamic part being the result of $read) to monitor how many time each line is called.
An uniform result is expected, but regardless of the number of lines in the file, the last line is always picked up much more often than the others.
Note that the others lines are called uniformly.

One example with /test_read 100:

* test_read 1:999 2:961 3:990 4:1046 5:975 6:995 7:956 8:992 9:998 10:1012 11:996 12:983 13:992 14:932 15:957 16:948 17:973 18:985 19:976 20:1002 21:1012 22:983 23:977 24:1011 25:972 26:1061 27:1023 28:1021 29:1028 30:1012 31:998 32:982 33:975 34:934 35:960 36:976 37:994 38:1035 39:993 40:1046 41:1030 42:1032 43:1002 44:957 45:1010 46:997 47:886 48:1022 49:972 50:976 51:963 52:1056 53:997 54:1006 55:1042 56:1012 57:958 58:971 59:979 60:985 61:1008 62:958 63:969 64:1002 65:955 66:983 67:999 68:976 69:992 70:992 71:969 72:993 73:1025 74:962 75:1010 76:1020 77:1003 78:989 79:942 80:966 81:968 82:977 83:999 84:964 85:1034 86:1015 87:969 88:960 89:961 90:1011 91:964 92:997 93:933 94:1011 95:927 96:1035 97:1063 98:957 99:1029 100:1999


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: $read()'s random function is not uniform [Re: Wims] #245659 01/05/14 05:38 AM
Joined: Jun 2003
Posts: 81
T
TRT Offline
Babel fish
Offline
Babel fish
T
Joined: Jun 2003
Posts: 81
confirmed, nice catch

Re: $read()'s random function is not uniform [Re: Wims] #245660 01/05/14 09:18 AM
Joined: Dec 2002
Posts: 4,584
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,584
Thanks this issue has been fixed for the next version.