Help with routines choosing unrepeated data from an array
Posted: Fri Jan 07, 2011 7:22 am
Hi thanks for running these boards.
I am stuck trying to write a routine in a larger programme.
I want to choose data randomly from an array and write it to a new array. It doesn't matter which order it arrives in as long as data is not repeated in the new array.
I am not using days of the week but have chosen them as an example to hopefully make things clearer
The routine below allows repetition e.g. friday, monday, friday
How do i code it so that three unrepeated pieces of data will be chosen?
I have tried various ways with subroutines but keep coming unstuck.
Can anyone help?
Thanks in advance.
CLS
CLEAR
RANDOMIZE TIMER
DIM weekday$(7)
FOR a = 1 TO 7
READ weekday$(a)
NEXT a
DIM newlist$(3)
FOR z = 1 TO 3
pickday = INT(RND * 7) + 1
newlist$(z) = weekday$(pickday)
NEXT z
FOR a = 1 TO 3
PRINT newlist$(a)
NEXT a
DATA "monday","tuesday", "wednesday", "thursday","friday","saturday","sunday"
I am stuck trying to write a routine in a larger programme.
I want to choose data randomly from an array and write it to a new array. It doesn't matter which order it arrives in as long as data is not repeated in the new array.
I am not using days of the week but have chosen them as an example to hopefully make things clearer
The routine below allows repetition e.g. friday, monday, friday
How do i code it so that three unrepeated pieces of data will be chosen?
I have tried various ways with subroutines but keep coming unstuck.
Can anyone help?
Thanks in advance.
CLS
CLEAR
RANDOMIZE TIMER
DIM weekday$(7)
FOR a = 1 TO 7
READ weekday$(a)
NEXT a
DIM newlist$(3)
FOR z = 1 TO 3
pickday = INT(RND * 7) + 1
newlist$(z) = weekday$(pickday)
NEXT z
FOR a = 1 TO 3
PRINT newlist$(a)
NEXT a
DATA "monday","tuesday", "wednesday", "thursday","friday","saturday","sunday"