|
Matteo Newbie
Joined: 31 Aug 2002 Posts: 6 Location: USA
|
Posted: Sat Aug 31, 2002 5:47 am
Random number generator |
I need help building a random number generator in ZMud. I need to be able to generate a random number of variables between 1 and 30, with each variable having a unique (no duplicates) value between 1 and 36.
|
|
|
|
Retrovirus Wanderer
Joined: 13 Jul 2002 Posts: 51 Location: Malaysia
|
Posted: Sat Aug 31, 2002 7:17 am |
%random(1, 30)=number
Cameth
Saweth
Fledeth my asseth offeth |
|
|
|
TonDiening GURU
Joined: 26 Jul 2001 Posts: 1958 Location: Canada
|
Posted: Sat Aug 31, 2002 7:42 am |
How about something like:
#VARIABLE V_Random_values ""
#LOOP 36 {#ADDITEM V_Possibles %i}
V_Random_Num_of_variables=%random( 1, 30)
#LOOP @V_Random_Num_of_variables {#VARIABLE V_Pick %item( @V_Possibles, %random( 1, %numitems( @V_Possibles)));#ADDITEM V_Random_values @V_Pick;#DELITEM V_Possibles @V_Pick}
#SHOW Chose @V_Random_Num_of_variables values being @V_Random_values
Ton Diening
Edit 11Sep02 14:03: Tested 6.16 win98se and no issues. Outputs:
Chose 7 values being 26|22|12|25|29|27|35 |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Aug 31, 2002 1:52 pm |
A random number of variables (1-30)
Each variable with a different random number (1-36)
Why?
It's unlikely this is the best approach to your problem.
LightBulb
Senior Member |
|
|
|
Matteo Newbie
Joined: 31 Aug 2002 Posts: 6 Location: USA
|
Posted: Sun Sep 08, 2002 6:46 pm |
I created the code as follows:
#VARIABLE V_Random_values ""
#LOOP 36 {#ADDITEM V_Possibles %i}
#LOOP 28 {
#VARIABLE V_Pick %item( @V_Possibles, %random( 1, %numitems( @V_Possibles)))
#ADDITEM V_Random_values @V_Pick
#DELITEM V_Possibles @V_Pick
}
#SHOW values @V_Random_values
Everything works (no bugs) but ZMud hangs and wont respond to any input. Using Crahsguard I can interrupt it and get it to respond again, and it spits out the random string of numbers. Any ideas why it is hanging? Recursion error? Stack overflow?
Help! |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sun Sep 08, 2002 10:06 pm |
If zMUD hangs then everything doesn't work. You never answered my previous questions, but it appears you just want 28 (or is it 30?) random numbers and it's okay if they are all in the same variable. That's significantly different from your previous request (a random number of random numbers).
It's not a recursion problem because there's no recursion.
There's no need for the first #LOOP. It can be replaced with a single variable command.
#VAR Possibles {1|2|3|4|...|34|35|36}//You'll need to fill in the remaining numbers
Since you know that there will be 28 numbers at the end, and that they must all be different, then that means you'll have every number in the list except for 8. So instead of picking 28 to keep, you can choose 8 to delete and get the same result 3 1/2 times faster. Of course, the result will be in numerical order instead of random order.
#LOOP 1,8 {#DELNITEM Possibles %random(1, %numitems(@Possibles)}
#SHOW {@Possibles}
LightBulb
Senior Member |
|
|
|
Matteo Newbie
Joined: 31 Aug 2002 Posts: 6 Location: USA
|
Posted: Sun Sep 08, 2002 11:57 pm |
Your approach does seem to make more sense, however when I copy paste into zmud I get a syntax error. This is what I have in the macro:
#VAR Possibles {1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36}
#LOOP 1,8 {#DELNITEM Possibles %random(1, %numitems(@Possibles)}
#SHOW {@Possibles}
When I run this one it doesn't hang the system (good!) but still will not display the numbers. The fact that this displays them in numerical order is actually a good thing. Thanks for the input. If you can help with the syntax error I would appreciate it.
The reason I am building this is there is a casino in my mud that I want to generate random values for betting (roulette). 24-30 variables, each with a random unique value between 1 and 36. I already have the #PROMPT to allow me to put in the number of variables that I want to bet that round, so I didn't specifiy it in my request. I also have the #CAP to capture the output and place the bets. I hope that answers your question. It's not like I was trying to solve a problem with a number generator, the number generator *was* the problem. |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Mon Sep 09, 2002 2:16 am |
The syntax error seems to be a missing close paranthesis on the LOOP line. Corrected line as folows:
#LOOP 1,8 {#DELNITEM Possibles %random(1, %numitems(@Possibles))}
I have trouble understanding your statements,
quote:
...but still will not display the numbers. The fact that this displays them in numerical order is actually a good thing.
Is it displaying them or not? What other functionality do you need? |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Mon Sep 09, 2002 4:36 am |
You'd think by now I'd know to count all my parentheses and other delimiters before finishing a post. Oh well...
Thanks for catching it, Vijilante.
LightBulb
Senior Member |
|
|
|
Matteo Newbie
Joined: 31 Aug 2002 Posts: 6 Location: USA
|
Posted: Wed Sep 11, 2002 8:05 pm |
The number generator works, but ZMud freezes when I try to capture the output to variables. I have the following code:
#TR {&slot1~|&slot2~|&slot3~|...&slot28}
#GAG
Zmud invariably hangs and I have to use the close program dialog box to close the program. Windows says it is not responding.
Is anyone else able to recreate the crash? Is there an obvious fix that eludes me? Any help would be appreciated.
I am running Win98b and Zmud 6.16. |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Wed Sep 11, 2002 11:40 pm |
You don't really gain anything by transferring the numbers to individual variables. Just use the %item function.
Instead of "@slot15" use "%item(@possibles, 15)"
If you want to preserve the current list, so you'll have it while you're generating a new list, just put it in another variable. Of course, it should take less than a second to generate a new list.
#VAR slots {@possibles}
%item(@slots, 15)
However, if you still want individual variables, you can use #LOOP and #VAR with %numitems and %item.
#LOOP %numitems(@possibles) {#VAR slot%i {%item(@possibles, %i)}}
LightBulb
Senior Member |
|
|
|
|
|