Posts: 285
Threads: 154
Joined: Mar 2016
Reputation:
0
I just need to make random numbers and i want that all them be different:
How to understand for what?
Posts: 3,324
Threads: 96
Joined: Sep 2013
Wait... So basically you want all of the values to be random (between 0 and 9), but you don't want any of them to be the same?
That's easier than everybody here is making it. Just fill an array and shuffle it!
pawn Код:
//Function
ShuffleArray(arr[], size = sizeof(arr)) {
for(new i = size - 1, j, t; i > 0; i--) {
j = random(i + 1);
t = arr[i];
arr[i] = arr[j];
arr[j] = t;
}
}
//Example
main() {
new random_array[10];
for(new i; i < 10; i++) {
random_array[i] = i;
}
ShuffleArray(random_array);
for(new i; i < 10; i++) {
printf("%i: %i", i, random_array[i]);
}
ShuffleArray(random_array);
for(new i; i < 10; i++) {
printf("%i: %i", i, random_array[i]);
}
ShuffleArray(random_array);
for(new i; i < 10; i++) {
printf("%i: %i", i, random_array[i]);
}
}
Posts: 285
Threads: 154
Joined: Mar 2016
Reputation:
0
No only between 0-9 this inverval can be 0-100 0-1000 and so on any number.
And not only random1,random2,random3 it could be anything
Posts: 3,324
Threads: 96
Joined: Sep 2013
Quote:
Originally Posted by ScIrUsna
No only between 0-9 this inverval can be 0-100 0-1000 and so on any number.
And not only random1,random2,random3 it could be anything
|
There, edited my last post. All you need to do now it fill an array with the numbers you want then use the ShuffleArray function on it.
You could even do this for 1000 different numbers:
pawn Код:
new random_array[1000];
//Filling the array with consecutive numbers for the sake of this example
for(new i; i < 1000; i++) {
random_array[i] = i;
}
ShuffleArray(random_array);
for(new i; i < 1000; i++) {
printf("%i: %i", i, random_array[i]);
}