Jump to content
  • 0

How to correctly make a check for... ?


Question

Posted
setarray .array_list[0], 1, 2, 3, 4, 5;
set .random_variable, rand( 1,4 );
for( set .@a, 0; .@a < .random_variable; set .@a, .@a + 1 ) {
  setd( "Variable_" + .@a ), .array_list[ rand( getarraysize( .array_list) ) ];
  mes "" + getd( "Variable_" + .@a ) + "";
}

How to make non-repeatable "Variable_" + .@a for example if .random_variable > 1:

if .random_variable == 4: Variable_1 != Variable_2, Variable_1 != Variable_3, Variable_1 != Variable_4, Variable_2 != Variable_3, Variable_2 != Variable_4, Variable_3 != Variable_4

 

Is this possible to check it inside for( condition ) { statement }?

 

Thank you for any advises!

7 answers to this question

Recommended Posts

  • 0
Posted (edited)

So you want a random number of variables set to a random number from a given array correct, without any repeating values from said given array?

 

try this

    setarray .array_list[0], 1, 2, 3, 4, 5;
    set .random_variable, rand( 1,4 );
    copyarray .@temp_list[0],.array_list[0],getarraysize( .array_list);
    for( set .@a, 0; .@a < .random_variable; set .@a, .@a + 1 ) {
        .@i = rand( getarraysize( .@temp_list) )
        setd( "Variable_" + .@a ), .@temp_list[ .@i ];
        deletearray .@temp_list[.@i],1;
        mes .@a + ": " + getd( "Variable_" + .@a ) + "";
    }



Edit2: This Should Work

Edited by Stolao
  • Upvote 1
  • 0
Posted

If(getd("variable_"+rand(1,4)) == 5)

On phone so want type it all out but you get idea I hope

 

Not exactly what i mean...

 

1. We setup .array_list with VALUES: 1, 2, 3, 4, 5;

2. We generate random VALUE for .random_variable : could be from 1 to 4;

3. We processing with for( condition ) { statement } and SETUP "Variable_" + .@a with RANDOM value from .array_list : for example 1;

4. We continue do for( condition ) { statement } UNTIL we will have number of "Variable_" + .@a that equal to .random_variable

5. MAIN POINT: "Variable" + .@a is not repeatable, AGAIN: Variable_0 - one value; Variable_1 - different value IS NOT EQUAL to Variable_0;  Variable_2 - different value IS NOT EQUAL to Variable_1 AND IS NOT EQUAL to Variable_0;

Again: all Variable_X are unique...

 

Thank you again!

  • 0
Posted

So you want a random number of variables set to a random number from a given array correct, without any repeating values from said given array?

 

try this

    setarray .array_list[0], 1, 2, 3, 4, 5;
    set .random_variable, rand( 1,4 );
    copyarray .@temp_list[0],.array_list[0],getarraysize( .array_list);
    for( set .@a, 0; .@a < .random_variable; set .@a, .@a + 1 ) {
        .@i = rand( getarraysize( .@temp_list) );
        setd( "Variable_" + .@a ), .@temp_list[ .@i ];
        deletearray .@temp_list[.@i],1;
        mes .@a + ": " + getd( "Variable_" + .@a ) + "";
    }



Edit2: This Should Work

 

Working, trying to combine many time, need more time to test, thank you Sir!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...