|
Joined: Aug 2005
Posts: 1,052
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2005
Posts: 1,052 |
this is an example of my script
Btw yes I know looks confusing but end story is that a random nick is chosen from the channel and instead of producing that $nick right away it returns me the number in the list so I can issue quiz A to the first person and to the second person and third
summary: I need to turn 18 9 15 into 9 15 18
alias xr { %rand1 = $nick(#chat,$nick(#chat,$rand(1,$nick(#chat,0)))) %rand2 = $nick(#chat,$nick(#chat,$rand(1,$nick(#chat,0)))) %rand3 = $nick(#chat,$nick(#chat,$rand(1,$nick(#chat,0)))) }
The problem I have is I can't control the order they come in and this is what I want so that if %rand1 = 15 % rand2 = 2 and rand3 = 7
Rand2 would be first second would be rand3 and third would be rand1
so that when I perform my script
ON *:INPUT:#:{ if (@QuizA == $1) { if ($nick(#,0) < 3) { return } else { msg # I've picked random users in # and lucky users are number %rand1,%rand2,%rand3 | quizAscript } } }
this is where I want the order so that $nicks start first from a - z
basically the script quizAscript starts small parts shown its a real lenghty script
alias quizAscript { msg #chat $readini(quiz.ini,firstq,data) }
ON *:text:*:#chat:{ if ($nick == $nick(#chat,%randfirst nick)) && ($readini(quiz.ini,firstq,answer) == answer) { msg #chat congrats $nick(#chat,%rand) | mode # +o $nick(#chat,%rand) } else { remove him blah blah go to next } }
so everything works perfectly except my nicks are not IN order.
sorry for the long post but was to show u the method in what I need done
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
|
|
|
|
Joined: Aug 2005
Posts: 1,052
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2005
Posts: 1,052 |
this is an example of my script
Btw yes I know looks confusing but end story is that a random nick is chosen from the channel and instead of producing that $nick right away it returns me the number in the list so I can issue quiz A to the first person and to the second person and third
summary: I need to turn 18 9 15 into 9 15 18
alias xr { %rand1 = $nick(#chat,$nick(#chat,$rand(1,$nick(#chat,0)))) %rand2 = $nick(#chat,$nick(#chat,$rand(1,$nick(#chat,0)))) %rand3 = $nick(#chat,$nick(#chat,$rand(1,$nick(#chat,0)))) }
The problem I have is I can't control the order they come in and this is what I want so that if %rand1 = 15 % rand2 = 2 and rand3 = 7
Rand2 would be first second would be rand3 and third would be rand1
so that when I perform my script
ON *:INPUT:#:{ if (@QuizA == $1) { if ($nick(#,0) < 3) { return } else { msg # I've picked random users in # and lucky users are number %rand1,%rand2,%rand3 | quizAscript } } }
this is where I want the order so that $nicks start first from a - z
basically the script quizAscript starts small parts shown its a real lenghty script
alias quizAscript { msg #chat $readini(quiz.ini,firstq,data) }
ON *:text:*:#chat:{ if ($nick == $nick(#chat,%randfirst nick)) && ($readini(quiz.ini,firstq,answer) == answer) { msg #chat congrats $nick(#chat,%rand) | mode # +o $nick(#chat,%rand) } else { remove him blah blah go to next } }
so everything works perfectly except my nicks are not IN order.
sorry for the long post but was to show u the method in what I need done Ill answer my own question by saying type /help $sorttok i know its sad.
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
|
|
|
|
Joined: Sep 2003
Posts: 261
Fjord artisan
|
Fjord artisan
Joined: Sep 2003
Posts: 261 |
Lol. Hey it happens to the best of us .
We don't just write the scripts, we put them to the test! (ScriptBusters)
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
consider using $addtok as well to eliminate the same nick being randomly choosen twice or more, use a while ($numtok() < 3) to keep going untill u have the 3 then sort em after it.
|
|
|
|
Joined: Aug 2005
Posts: 1,052
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2005
Posts: 1,052 |
im having a sort problem of something like this now
9 5 19 40 1 4 20 40 4 5 6 7
where 1 4 20 40
a vertical sort...
hmph
even if i Loop through and do a $gettok(Val,1,32) i still get it unsortted
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
I see "9 5 19 40" doesnt look right, but you didnt explain what your problem is clearly to me, i didnt see anything wrong with "1 4 20 40" which ever it is heres a simple example of gaining 10 random numbers from 1 to 100 and then placing them in order alias ex {
var %t = 10, %l
while ($numtok(%l,32) < %t) { var -s %l = $addtok(%l,$rand(1,100),32) }
var -s %l = $sorttok(%l,32,n)
} NB the ,n on the $sorttok, becuase i wanted them numericly sorted ie: 2 to 9 before 10-19 etc.
|
|
|
|
Joined: Feb 2004
Posts: 206
Fjord artisan
|
Fjord artisan
Joined: Feb 2004
Posts: 206 |
Here is an alternative approach that doesn't use sorting algorithms (but by adding a random amount to the previous number). This is not a perfect idea, there are some "statistical" issues which may reduce "randomness" - but this approach could be useful in some contexts:
; Working off DaveC's Code
alias ex {
var %t = 10
var %curr_rand = $rand(1,10)
var %l = %curr_rand
while ($numtok(%l,32) < %t) {
%curr_rand = $calc(%curr_rand + $rand(1,10))
var -s %l = $addtok(%l,%curr_rand,32)
}
}
; Not tested
Personally, I think that the $sorttok solution is neater! Cheers, DK
Darwin_Koala
Junior Brat, In-no-cent(r)(tm) and original source of DK-itis!
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
Id say theres some satistical descrepency for sure! Chance of value "1" appearing 1:10 Chance of value "100" appearing 1:10000000000
However If the randomness called for such incremental type steps that is a good example. I amagined a jumping frog, max jump size of 10 min of 1, then the results would be the most suited.
|
|
|
|
Joined: Aug 2005
Posts: 1,052
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2005
Posts: 1,052 |
You know what is happening the first or second or 3rd val might be = to other vals previously called
like 9 17 9 2
this is why the vertical sorttok might not be working, I have to find a way to keep looping the identical token till its changed and not matching
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
i have already shown u how to deal with that $addtok.
$addtok well not add a duplicate token, so u simply set up a loop as follows...
var %list.of.tokens, %number.of.tokens.you.want = 3 while ($numtok(%list.of.tokens,32) < %number.of.tokens.you.want) { var %list.of.tokens = $addtok(%list.of.tokens,$rand(1,100),32) } ; ^ to loop continues untill u have the correct number of tokens ; ^ since $addtok wont allow duplicate tokens if it gets one its already got then the list does not grow and the while loop repeats. var %list.of.tokens = $sorttok(%list.of.tokens,32,n) ; ^ lastly sort em!
|
|
|
|
Joined: Aug 2005
Posts: 1,052
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2005
Posts: 1,052 |
That I did already but this is what I meant sorry for not being clear The evaluation horizontally is perfect, the vertical sortting is what im trying to achieve and + I keep getting double evals shown in red at the bottom then more at the bottom of the number list youll see a small script implementing DaveC's script in a another while evaluation to see what i mean im trying to sort this vertical like for example if you carry these numbers to excel you can highlight them all the data sort them... this is what i mean but want mirc to sort them vertically and remove duplicates 1 2 8 1 5 7 0 3 7 2 3 7 2 3 70 3 6 2 7 9 2 4 7 6 8 9 5 6 7 6 7 8 4 5 8 0 2 9
alias rodd {
var %list.of.tokens, %number.of.tokens.you.want = 3
while ($numtok(%list.of.tokens,32) < %number.of.tokens.you.want) { var %list.of.tokens = $addtok(%list.of.tokens,$rand(0,9),32) }
var %list.of.tokens = $sorttok(%list.of.tokens,32,n)
echo -a %list.of.tokens
}
alias toks {
var %x = 1
while (%x <= 980) {
rodd
inc %x
}
}
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
So you want a horizontally and vertically sorted array that doesn't repeat the exact same line twice?
alias make.array {
;$1=num of rows, $2=num of cols, $3=rand lower limit, $4=rand upper limit
if ($+($1,$2,$3,$4) !isnum) { echo -a /make.array: Invalid parameters | return 0 }
if ($nCr($calc($4 - $3),$2) < $1) { echo -a /make.array: Invalid data range | return 0 }
if ($window(@sarray)) window -c @sarray
window -ns @sarray
while ($line(@sarray,0) < $1) {
var %srow = $make.line($2,$3,$4)
if (%srow < 0) return 0
aline -n @sarray %srow
}
return 1
}
alias make.line {
;$1=num of cols, $2=rand lower limit, $3=rand upper limit
if ($calc($3 - $2) < $1) { echo -a /make.line: Invalid data range | return -1 }
while ($numtok(%sline,32) < $1) var %sline = $sorttok($addtok(%sline,$rand($2,$3),32),32,n)
return %sline
}
alias factorial {
;$1=n
var %n = 1, %c = 0
while (%c < $1) { inc %c | %n = $calc(%n * %c) }
return %n
}
alias nCr {
;$1=n, $2=r
return $calc($factorial($1) / ($factorial($2) * $factorial($calc($1 - $2))))
}
Usage: //echo -a $make.array(<num of lines>,<num of cols>,<$rand lower limit>,<$rand upper limit>) Returns: 1 on success, 0 on failure The data is output to the @sarray window if the command is successful. The code will stop in the following conditions: - Any of the parameters are non-numerical - The requested number of columns is larger than the maximum number of columns possible using the given upper and lower limits. - The requested number of rows is larger than the maximum number of possible combinations. Post questions or bugs. -genius_at_work
|
|
|
|
Joined: Aug 2005
Posts: 1,052
Hoopy frood
|
OP
Hoopy frood
Joined: Aug 2005
Posts: 1,052 |
thats perfect man you are a true genius at work
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
|
|
|
|
|