I've got Psuedo random

by London (no login)

 
I see your problem here. So my solution would be to make an index of all the characters you want to print, and mix the INDEX up.

This solution creats an index of 700 rows and columns, 7 rows by 100 characters. Make it more if you need more. Then it fills each array element in order, with the rows and columns (1 to 100 for each of the rows).

The next step is to shake up the index. I've made a very simple randomizing routine here, I'm sure you can come up with something better. Now when you print the characters, you simply reference the index (in order) and print the corresponding character.

For example, index(1) may point to row 4, column 99, so print the character in that location; index(2) may next point to row 1, column 623, so print that character. All the characters get printed in an apparently random sequence.

To keep your eye from catching the pattern the characters appear on screen each time, start the index at a random spot every time. Start printing at say index(173) go till you hit 700, then loop back to 172. This will give an extra random appearance.

I've placed some code here that is untested since I don't have access to Qbasic at work. I hope you can salvage something from it, if not let me know and I'll try some code at home.



'Make and array of rows and columns the size you need, i.e. rows * columns
'here I used 7 rows, by 100 columns
TYPE indexStats
Column as integer
Row as integer
END TYPE
DIM index(1 to 700) as indexStats

'This is your array of characters, I'm not sure how you have yours set up
DIM Characters(1 to 100, 1 to 7) as String*1

'Fill the index array with numbers in sequence
'The fancy index references (a*b+b-1) is to marry a two dimensional array
'with a 1 dimensional array. a*b+b-1 seems to work in my head, but you may
'need to tweak it
FOR a = 1 to 100
FOR b = 1 to 7
index(a*b+b-1).Column = a
index(a*b+b-1).Row = b
NEXT b
NEXT a

'Randomize the array, I do it by swaping array elements 700 times, not very
'efficient, but it gets the job done
FOR a = 1 to 700
b = INT(RND*700) + 1
SWAP index(a).Column, index(b).Column
SWAP index(a).Row, index(b).Row
NEXT a

'Now printing the characters
'b is that start point I mentioned earlier, it starts at a random point in
'the index, then loops around (notice the if statement in there) from the
'beginning of the array once it passes the maximum size of the index array
'which is 700 in this case
'LOCATE the proper place on screen, then print the character. I may have the
'row and column variables in that locate statement mixed up, I always do.
b = INT(RND*700)+1
FOR a = 1 to 700
b = b + 1
IF b > 700 THEN b = 1
LOCATE index(b).Column, index(b).Row
PRINT Characters(index(b).Column, index(b).Row)
NEXT a




Is this what you're looking for?

Posted on Sep 27, 2011, 9:41 AM

Respond to this message   

Return to Index

Response TitleAuthor and Date
yes butlisztfr on Sep 28
The idea is ...Lisztfr on Oct 3
Better one :Lisztfr on Oct 3

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement