How to shuffle ds_list() range of consecutive numbers

I'm trying to develop a program in which you shuffle an array of numbers(numerals) example I make a "For" loop (i = 40, i <= 40, i ++)
and generate the following value for i


If I set an array (Array 1 - 40)
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40
I would like to shuffle these consecutive 40 numbers(numerals)

Or
If I set an array 41-80
41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80
I would like to shuffle these consecutive 40 numbers(numerals)

Or
If I set an Array 81-120
81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120
I would like to shuffle these consecutive 40 numbers(numerals)

Or
If I set an Array 121-160
121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160
I would like to shuffle these consecutive 40 numbers(numerals)

Or
If I set an Array 161-200
161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200
I would like to shuffle these consecutive 40 numbers(numerals)
............. The process goes on and on and on.... A code which shuffles 40 consecutive numbers.

I'm currently working with the following ds_list_shuffle() code:


global.list = ds_list_create()
for (global.i = 1; global.i <= 40; global.i ++) {
global.list[| global.i] = global.i;
}
ds_list_shuffle(global.list);


for (global.n = 0; global.n < ds_list_size(global.list); global.n ++) {
global.array[global.n] = global.list[| global.n];
}
ds_list_destroy(global.list);

I'm currently having difficulty shuffling 40 consecutive numbers whether it be 0-40,40-80,80-120......
Any help would be greatly appreciated
 

Bart

WiseBart
Not sure if your issue is clear to me.
Can you get it to work for values ranging from 1-40 but not for other ranges?

If that's the case, you're only missing an offset. The loop variable can simply range from 0 to (number_of_values - 1) (or from 1 to number_of_values if you want).
GML:
global.start= 80;                            // Start at the value 80

global.list = ds_list_create();
var i;

for (i = 0; i < 40; i ++) {                  // 40 is the number of consecutive numbers you want
global.list[| i] = global.start + i;         // Add the offset to the value, not to the list index
}
ds_list_shuffle(global.list);
When assigning the values to global.array you also don't add the offset, like this:
GML:
for (i = 0; i < ds_list_size(global.list); i ++) {
global.array[i] = global.list[| i];           // Just copy each value
}
ds_list_destroy(global.list);
 
Last edited:
Not sure if your issue is clear to me.
Can you get it to work for values ranging from 1-40 but not for other ranges?

If that's the case, you're only missing an offset. The loop variable can simply range from 0 to (number_of_values - 1) (or from 1 to number_of_values if you want).
GML:
global.start= 80;                            // Start at the value 80

global.list = ds_list_create();
var i;

for (i = 0; i < 40; i ++) {                  // 40 is the number of consecutive numbers you want
global.list[| i] = global.start + i;         // Add the offset to the value, not to the list index
}
ds_list_shuffle(global.list);
When assigning the values to global.array you also don't add the offset, like this:
GML:
for (i = 0; i < ds_list_size(global.list); i ++) {
global.array[i] = global.list[| i];           // Just copy each value
}
ds_list_destroy(global.list);

Thank You very much for the help... yes I didn't have the global.start on initiating on a particular value.
I also placed randomize(); at the beginning of the code so it wont be predictable on how it's going to start. Thanks a lot Bart you have been a great help.
 
Top