Author |
Message |
Azzy
|
Posted: Mon Nov 03, 2003 6:20 pm Post subject: Rand.Int |
|
|
how can you make it so it can only use one number one time? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Mazer
|
Posted: Mon Nov 03, 2003 6:41 pm Post subject: (No subject) |
|
|
could you explain what you mean? |
|
|
|
|
|
poly
|
Posted: Mon Nov 03, 2003 6:46 pm Post subject: (No subject) |
|
|
I think he means, have say a randint randomizing from 1 to 6 and only having 1 show up once, 2 show up once etc. |
|
|
|
|
|
Azzy
|
Posted: Mon Nov 03, 2003 6:50 pm Post subject: (No subject) |
|
|
exactly like poly said.like for the one i'm doing i have 52 but each one can only show up once.so there can only be 1 of the 35 variable in the array. |
|
|
|
|
|
poly
|
Posted: Mon Nov 03, 2003 6:54 pm Post subject: (No subject) |
|
|
ok so have the randint and have an array keeping track of the numbers and have either an array or variable making sure no numbers are the same. I understand what you mean and how to do it, just I am shitty at explaining things just like above! |
|
|
|
|
|
Tony
|
Posted: Mon Nov 03, 2003 8:10 pm Post subject: (No subject) |
|
|
What you should do is to have an array 1 to w/e largest number you want. Then you use Rand.Int to randombly pick an index of the number. It will be your first result. Then take that array element out and shift the array so that there're no gaps.
So each time, you pick a random number from 1 to n-try. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
nis
|
Posted: Thu Nov 06, 2003 6:56 pm Post subject: (No subject) |
|
|
Like tony said create an array
but create an array 1 to the highest num of boolean
and put the randint inside a loop
when a random number is choosen go to the array of that number and set it to true. and then exit the loop. If the array is allready true then have it pick another number
var Array : array 1 .. 6 of boolean init(false,false,false,false,false,false)
var num : int
loop
randint(num,1,6)
if not (Array(num)) then
Array(num) = true
exit
end if
end loop
%Then do what ever you have to do |
|
|
|
|
|
Tony
|
|
|
|
|
Sponsor Sponsor
|
|
|
nis
|
Posted: Fri Nov 07, 2003 12:00 am Post subject: (No subject) |
|
|
damn
That is good code
*cough* Watch your back *cough*
Showing me up like that |
|
|
|
|
|
Tony
|
|
|
|
|
Azzy
|
Posted: Fri Nov 07, 2003 9:10 pm Post subject: (No subject) |
|
|
There was a problem with the code.That is for an int array but I need that code for a string array.Is there any way you can change that? |
|
|
|
|
|
Tony
|
Posted: Fri Nov 07, 2003 9:28 pm Post subject: (No subject) |
|
|
You asked for numbers. Quote: use one number one time
ether way. You get a list of numbers - use them as your array indexes to pick stings out. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
|