random
#1

Hi,

Код:
new random1 = random(10);
new random2 = random(10);
new random3 = random(10);
I want to make random but in next random i don't want that random which was for ex if i get random1

Код:
random1 = 5
random2 never be 5

and if random2 will be 3

random3 will be never 5 and 3
Reply
#2

Random For?
Reply
#3

I just need to make random numbers and i want that all them be different:

How to understand for what?
Reply
#4

Try this

Код:
new random1 = random(10);
new random2 = random(10); if(random2 == random1) random2  = random(10);
new random3 = random(10); if(random3 == random1 || random3 == random2) random3 = random(10);
...
Reply
#5

PHP код:
new
    
rand1 random(10),
    
rand2 random(9),
    
rand3 random(8)
;
if(
rand2 >= rand1rand2++;
if(
rand1 rand2) {
    if(
rand3 >= rand1rand3++;
    if(
rand3 >= rand2rand3++;
} else {
    if(
rand3 >= rand2rand3++;
    if(
rand3 >= rand1rand3++;

Reply
#6

Код:
new random1 = random(10);
new random2 = random(10);
new random3 = random(10);
random2e1_check:
if(random2 == random1)
{
    random2 = random(10);
    goto random2e1_check;
}
random3e2_check:
if((random3 == random2) || random3 == random1)
{
    random3 = random(10);
    goto random3e2_check;
}
Reply
#7

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]);
    }
}
Reply
#8

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
Reply
#9

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]);
    }
Reply
#10

But it prints 1000 times and it writes in 1000 variables? how it look when i want random(1000) but i need have for example in 5 variables.

Код:
format( string, 50,"%d %d %d %d %d", Random[ 0 ],Random[ 1 ],Random[ 2 ],Random[ 3 ],Random[ 4 ] );
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)