HI FRIENDS
I have questions regarding drawing random numbers from variable.
I want to get number between 1 and 100.
Say I get 4
Then I want to do it again but not draw 4 again. How can I do this?
Ok 2nd question:
I do this many times.
So for example after 10 draws I have 1, 2, 3, 4, 5 ... 10. These numbers can not be used in a draw. But then something happens in game and I can use one of the numbers, for example 3, again.
So I draw again only now I can not draw 1, 2 ,4, 5 ... 10.
Any way to do this?
THX
Random number variable without repeat
● ARCHIVED · READ-ONLY
-
-
I actually have a script for this. I'm planning to post it to these forums soon but if you want it now, use: http://www.pavilionboards.com/forum/showthread.php?p=672843#post672843
While that script is primarily designed for playing cards, it includes all the functionality you'll need to make a set of numbers, pull them out of the pool of available numbers as they're chosen, and return them to the pool at any time you like. -
Can pulling 1 number be made to make another number unpullable as well?I actually have a script for this. I'm planning to post it to these forums soon but if you want it now, use: http://www.pavilionboards.com/forum/showthread.php?p=672843#post672843
While that script is primarily designed for playing cards, it includes all the functionality you'll need to make a set of numbers, pull them out of the pool of available numbers as they're chosen, and return them to the pool at any time you like. -
Just use a second variable, and compare it with the first. So after you already have the first one and set it to var1, you'd do:HI FRIENDS
I have questions regarding drawing random numbers from variable.
I want to get number between 1 and 100.
Say I get 4
Then I want to do it again but not draw 4 again. How can I do this?
var2 = random
if var2 == var1
[jump to top, start again]
else
do whatever
var1 = var2
end -
If you're doing it systematically, yes. For example, if you want pulling a certain number to disable the next two numbers (like pulling #6 would disable #7 and #8), you would use the commands $game_party.pullcard($game_variables[13] + 1) and $game_party.pullcard($game_variables[13] + 2), where Variable 13 is the variable you specified as the Card_Holder variable.Can pulling 1 number be made to make another number unpullable as well?
I didn't program it with this in mind, but I think it should work just fine. -
Ok cool perfect, the numbers I would want to be removed are grouped together like that anyway. I'm assuming negative numbers work as well, right(aka -1 means number 12 would be removed)?If you're doing it systematically, yes. For example, if you want pulling a certain number to disable the next two numbers (like pulling #6 would disable #7 and #8), you would use the commands $game_party.pullcard($game_variables[13] + 1) and $game_party.pullcard($game_variables[13] + 2), where Variable 13 is the variable you specified as the Card_Holder variable.
I didn't program it with this in mind, but I think it should work just fine. -
If you pull a number then check to see if you've used it before and if you have, jump back to the top again, you could find yourself in a very, very long loop.
Better to create an array containing all the numbers you want to use, then pull numbers randomly from that array - when you select a number, remove it and it won't be available to select again. Then if you want to add a number back in, you can do that too.
To set up:
Code:To get a number:Script: $game_variables[1] = []100.times do i $game_variables[1].push(i)end
Code:To add a number back (3, for example):Control Variables [0002: Random Number] = Script: $game_variables[1].delete_at(rand($game_variables[1].size))
Code:You would have to monitor to see if the array is empty after pulling a number from it, and decide what to do in that case - don't pull a number? Repopulate it with all available numbers again?Script: $game_variables.push(3) -
Oh, maybe I misunderstood -- I thought his first question was asking about simply not repeating the *last* number pulled, which is what I was responding to. Yes, OP, if both your questions were about the same system ("pulling cards"), ignore my post. :)If you pull a number then check to see if you've used it before and if you have, jump back to the top again, you could find yourself in a very, very long loop.
-
Thx for reply all.
Wavelength thx brah that does look like what I need. I hope to make it simple though so I want to see first if I can use Shaz's approach.
I tried to do it. I only need up to 10 so I put $game_variables[1] = [1, 2, etc., 10] in an event script command. I put a message \V[1] to show that the array is populated. Great success so far.
But then i try to get a number. I try put the part after "Script:" in a script box for control variable but it doesnt fit all.It cuts off at the "v" of the 2nd $game_variables. So it crashes then.
Putting back a number does work.
I intend to put a variable +1 every time a number is pulled and -1 if put back to monitor how many numbers are pulled. I'll make it so u can not pull the last number in the array so will never be empty.
So I only dont know how to do the second step.
Can u help me further?
If you pull a number then check to see if you've used it before and if you have, jump back to the top again, you could find yourself in a very, very long loop.
Better to create an array containing all the numbers you want to use, then pull numbers randomly from that array - when you select a number, remove it and it won't be available to select again. Then if you want to add a number back in, you can do that too.
To set up:
Code:To get a number:Script: $game_variables[1] = []100.times do i $game_variables[1].push(i)end
Code:To add a number back (3, for example):Control Variables [0002: Random Number] = Script: $game_variables[1].delete_at(rand($game_variables[1].size))
Code:You would have to monitor to see if the array is empty after pulling a number from it, and decide what to do in that case - don't pull a number? Repopulate it with all available numbers again?Script: $game_variables.push(3) -
Oh yeah, I forgot that the script portion of Control Variables is limited. Do it in a normal script call then.
Code:If you're still using an older version of the maker that doesn't give you long script lines, put the break here:$game_variables[2] = $game_variables[1].delete_at(rand($game_variables[1].size))
Code:$game_variables[2] = $game_variables[1].delete_at(rand($game_variables[1].size)) -
It works. Really appreciate all the help :)
-
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.