J
James T. Rex
Guest
So I've got this little script that generates a random integer with an amount of digits entered by the user. I draw out the sum as well as all its constituting components but when the amount of digits is 18 or higher (and sometimes 17 or 16) it doesn't add up correctly - it can be higher or lower; and with even higher digit counts the final few numerals often get locked at 0. Since its only with really high numbers I was wondering if its an integer overflow problem which I wouldn't know how to verify or work around if this was the case.
(script is called gen_digits)
//PREP
no=0;
base=(power(10,argument0))/10;//base becomes a multiplycation of 10 made of digits equaling argument0
ds_list_clear(list_10);
//FIRST DIGIT
temp=irandom_range(1,9)*base;
ds_list_add(list_10,temp);
no+=temp;
//DESCENDING BASES
if argument0>=2
{for(i=argument0-1;i>0;i-=1)
{base/=10;
temp=irandom(9)*base;
ds_list_add(list_10,temp);
no+=temp;
}
}
//end returning no (list ext-established)
return no;
Its being called by an object with the following code:
Create event:
list_10=ds_list_create();
generated_10=0;
Press <ENTER> event:
generated_10=gen_digits(get_integer("No. size in digits",""));
Draw event:
draw_text(10,10,generated_10);
draw_text(1000,10,ds_list_size(list_10));
if ds_list_size(list_10)>0
{for(i=0;i<ds_list_size(list_10);i+=1)
{draw_text(10,25+(i*15),ds_list_find_value(list_10,i));
}
}
(script is called gen_digits)
//PREP
no=0;
base=(power(10,argument0))/10;//base becomes a multiplycation of 10 made of digits equaling argument0
ds_list_clear(list_10);
//FIRST DIGIT
temp=irandom_range(1,9)*base;
ds_list_add(list_10,temp);
no+=temp;
//DESCENDING BASES
if argument0>=2
{for(i=argument0-1;i>0;i-=1)
{base/=10;
temp=irandom(9)*base;
ds_list_add(list_10,temp);
no+=temp;
}
}
//end returning no (list ext-established)
return no;
Its being called by an object with the following code:
Create event:
list_10=ds_list_create();
generated_10=0;
Press <ENTER> event:
generated_10=gen_digits(get_integer("No. size in digits",""));
Draw event:
draw_text(10,10,generated_10);
draw_text(1000,10,ds_list_size(list_10));
if ds_list_size(list_10)>0
{for(i=0;i<ds_list_size(list_10);i+=1)
{draw_text(10,25+(i*15),ds_list_find_value(list_10,i));
}
}