Marakasmalan
2014-11-23 10:25:00 UTC
Good day Everybody
I made an effort to program a random number generator. In short, it should create 4 lists of six unique random numbers, from 1 to 49.
I was hoping somebody may take a look and advise where I have applied the wrong principles or inefficient methods.
<<
0. 'A' STO @reset counter for nr. of duplicate substitutions
1 4 START
1 6 START
RAND 49 * IP 1 + @Random number between 1 and 49
@Is there a difference between FLOOR & IP in this
@application?
NEXT
6 ->LIST SORT @put six numbers to a list and sort
1 5 FOR I @loop to check if numbers are duplicated
DUPDUP @two copies of list on stack for GET commands
I 1 + GET @get nth plus 1 number in list
I GET @get nth number in list
IF == @check if n = (n+1)
THEN
I @placeholder to place new number
RAND 49 * IP 1 + @new random number
PUT @replace duplicate nr. Any difference if I replaced n+1?
SORT @sort list
1 'I' STO @reset FOR-loop for re-checking with new nr
'A' INCR @counter to show number of substitutions
DROP @DROP value INCR placed on stack. Any way to avoid this
@step?
END @end IF loop
NEXT @end FOR loop
NEXT @end START loop
A @put counter value on stack
I'm not sure the above format of the program is correctly written (as far as convention goes) as I am not a programmer.
At this stage the program works and delivers the required results, but I am not sure That I am using the most efficient way with the best suited commands.
Would it be better to put the numbers in an array or is a list the best way?
Regards
Marakas
I made an effort to program a random number generator. In short, it should create 4 lists of six unique random numbers, from 1 to 49.
I was hoping somebody may take a look and advise where I have applied the wrong principles or inefficient methods.
<<
0. 'A' STO @reset counter for nr. of duplicate substitutions
1 4 START
1 6 START
RAND 49 * IP 1 + @Random number between 1 and 49
@Is there a difference between FLOOR & IP in this
@application?
NEXT
6 ->LIST SORT @put six numbers to a list and sort
1 5 FOR I @loop to check if numbers are duplicated
DUPDUP @two copies of list on stack for GET commands
I 1 + GET @get nth plus 1 number in list
I GET @get nth number in list
IF == @check if n = (n+1)
THEN
I @placeholder to place new number
RAND 49 * IP 1 + @new random number
PUT @replace duplicate nr. Any difference if I replaced n+1?
SORT @sort list
1 'I' STO @reset FOR-loop for re-checking with new nr
'A' INCR @counter to show number of substitutions
DROP @DROP value INCR placed on stack. Any way to avoid this
@step?
END @end IF loop
NEXT @end FOR loop
NEXT @end START loop
A @put counter value on stack
I'm not sure the above format of the program is correctly written (as far as convention goes) as I am not a programmer.
At this stage the program works and delivers the required results, but I am not sure That I am using the most efficient way with the best suited commands.
Would it be better to put the numbers in an array or is a list the best way?
Regards
Marakas