Phenomena Posted November 22, 2015 Group: Members Topic Count: 14 Topics Per Day: 0.00 Content Count: 94 Reputation: 4 Joined: 10/31/12 Last Seen: February 13, 2022 Share Posted November 22, 2015 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! Quote Link to comment Share on other sites More sharing options...
0 Stolao Posted November 22, 2015 Group: Developer Topic Count: 48 Topics Per Day: 0.01 Content Count: 1443 Reputation: 344 Joined: 10/17/12 Last Seen: Sunday at 01:58 PM Share Posted November 22, 2015 (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 November 23, 2015 by Stolao 1 Quote Link to comment Share on other sites More sharing options...
0 Stolao Posted November 22, 2015 Group: Developer Topic Count: 48 Topics Per Day: 0.01 Content Count: 1443 Reputation: 344 Joined: 10/17/12 Last Seen: Sunday at 01:58 PM Share Posted November 22, 2015 If(getd("variable_"+rand(1,4)) == 5) On phone so want type it all out but you get idea I hope Quote Link to comment Share on other sites More sharing options...
0 Phenomena Posted November 22, 2015 Group: Members Topic Count: 14 Topics Per Day: 0.00 Content Count: 94 Reputation: 4 Joined: 10/31/12 Last Seen: February 13, 2022 Author Share Posted November 22, 2015 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! Quote Link to comment Share on other sites More sharing options...
0 Phenomena Posted November 23, 2015 Group: Members Topic Count: 14 Topics Per Day: 0.00 Content Count: 94 Reputation: 4 Joined: 10/31/12 Last Seen: February 13, 2022 Author Share Posted November 23, 2015 No, Sir, still have make duplicates. Quote Link to comment Share on other sites More sharing options...
0 Stolao Posted November 23, 2015 Group: Developer Topic Count: 48 Topics Per Day: 0.01 Content Count: 1443 Reputation: 344 Joined: 10/17/12 Last Seen: Sunday at 01:58 PM Share Posted November 23, 2015 you read it too soon, i had to fix it above No, Sir, still have make duplicates. notice my edit is after your reply -..- Quote Link to comment Share on other sites More sharing options...
0 Phenomena Posted November 23, 2015 Group: Members Topic Count: 14 Topics Per Day: 0.00 Content Count: 94 Reputation: 4 Joined: 10/31/12 Last Seen: February 13, 2022 Author Share Posted November 23, 2015 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! Quote Link to comment Share on other sites More sharing options...
0 Stolao Posted November 23, 2015 Group: Developer Topic Count: 48 Topics Per Day: 0.01 Content Count: 1443 Reputation: 344 Joined: 10/17/12 Last Seen: Sunday at 01:58 PM Share Posted November 23, 2015 Np, was a nice thought challenge before bed Quote Link to comment Share on other sites More sharing options...
Question
Phenomena
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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.