Jump to content
  • 0

How to correctly make a check for... ?


Phenomena

Question


  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.00
  • Content Count:  94
  • Reputation:   4
  • Joined:  10/31/12
  • Last Seen:  

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!

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

  • Group:  Developer
  • Topic Count:  48
  • Topics Per Day:  0.01
  • Content Count:  1443
  • Reputation:   337
  • Joined:  10/17/12
  • Last Seen:  

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
Link to comment
Share on other sites

  • 0

  • Group:  Developer
  • Topic Count:  48
  • Topics Per Day:  0.01
  • Content Count:  1443
  • Reputation:   337
  • Joined:  10/17/12
  • Last Seen:  

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

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

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.00
  • Content Count:  94
  • Reputation:   4
  • Joined:  10/31/12
  • Last Seen:  

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!

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.00
  • Content Count:  94
  • Reputation:   4
  • Joined:  10/31/12
  • Last Seen:  

No, Sir, still have make duplicates.

Link to comment
Share on other sites

  • 0

  • Group:  Developer
  • Topic Count:  48
  • Topics Per Day:  0.01
  • Content Count:  1443
  • Reputation:   337
  • Joined:  10/17/12
  • Last Seen:  

you read it too soon, i had to fix it above

 

No, Sir, still have make duplicates.


notice my edit is after your reply -..-

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.00
  • Content Count:  94
  • Reputation:   4
  • Joined:  10/31/12
  • Last Seen:  

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!

Link to comment
Share on other sites

  • 0

  • Group:  Developer
  • Topic Count:  48
  • Topics Per Day:  0.01
  • Content Count:  1443
  • Reputation:   337
  • Joined:  10/17/12
  • Last Seen:  

Np, was a nice thought challenge before bed

Link to comment
Share on other sites

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.

×
×
  • Create New...