RANDOMIZE command

Dear Team BASIC.

I am having difficulty, I am trying to open a file and print the contents of this file in a random order, but the data that has already been printed can't be printed again when the file is opened again. I believe the solution to this has something to do with the RANDOMIZE command, but I am not entirely sure.

Thanks team!

Comments

Thanks for your help, I think

Thanks for your help, I think I have it working now.

Oh, and I meant a metaphorical 'team', we are all part of Team BASIC, whether we like it or not, we all work together to help solve programming problems, just as a team works together to solve goals.

Thanks again.

Chris

Team

No, there really is a team as well as a community - it's small but it exists!

RANDOMIZE command

Christopher:

Your problem is not stated clearly.

I am guessing that what you have tried to do is to open a text file and place the lines of text into an array

(a) in such a manner that the lines of text in the array are not in the same order as they were in the file, or

(b) that after the lines were loaded into the array in normal order, they were printed in random order.

And, in either case, in order to do this, you have used the RND and RANDOMIZE features to "scramble" the order of the lines. Then, when you do this a SECOND time, the scrambled order of the lines was not the same as it was the first time. If the RANDOMIZE statement is present, this is exactly what would be expected: Different each time.

When using the RND function, a series of pseudo-random numbers is generated. Upon each execution of the program, the SAME set of "random" numbers will be produced.

However, if the RANDOMIZE statement is present at the beginning of the program (or at least prior to the use of the RND function), the RND function will generate a DIFFERENT set each time the program is run.

If you have the manual, this is supposed to be covered on pages 53-54, 282, 285-286, and 544 according to the index.
If you do not have the manual, I think a pdf of it can be downloaded somewhere on this website.

There is no "team", but I hope this helps.
Regards,
Mike C.

Still don't have randomize working! Help!

I still do not have the problem working, I am trying to open a file of numbers and after opening and reading from the file, I am trying to print random number from the file. Any help?

Thanks

Chris.

re: randomize

Still not quite sure what you are trying to do, but:

Randomize
dim numbers(10)
for n = 1 to 10
read numbers(n)
next n

data 1,2,3,4,5,6,7,8,9,10

for n = 1 to 10
let k = int(10*rnd) + 1
print numbers(k)
next n

end

The above program will print 10 numbers from the data chosen randomly but could have duplicates.

There are several ways to prevent duplicates, some more elgant than others (think of a card shuffling routine). One way would be to fill another array with the already printed numbers, one by one, and check each time a new number is randomly chosen that it is not in the 'old number' array. Be sure to clear the 'old number' array if going through the print process again without restarting the program. Below is another way. Choose a value that can't be in your number list and check each time a number is picked. If it is not the 'forbidden' value, print it and then set the array element to the forbidden value. See below where 999 is assumed not to be a legitimate value.

Randomize
dim numbers(10)
for n = 1 to 10
read numbers(n)
next n

data 1,2,3,4,5,6,7,8,9,10

let j = 0

do while j < 11
let k = int(10*rnd) + 1
if numbers(k) <> 999 then
print numbers(k)
let numbers(k) = 999
let j = j+1
end if
loop

end

rwt