Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I make a real randomized screensaver?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I was trying to create a simple randomized screensaver with the following
source code:
10 SCREEN 12
w = 0
LOCATE 20, 20
c = INT(RND * 16)
x = INT(RND * 640)
y = INT(RND * 480)
PSET (x, y)
DO

COLOR c

w = w + 1
IF w = 30000 THEN
GOTO 10
END IF
poep = INT(RND * 5)
IF poep = 1 THEN
x = x + 1
ELSEIF poep = 2 THEN
x = x - 1
ELSEIF poep = 4 THEN
y = y - 1
ELSEIF poep = 3 THEN
y = y + 1
END IF
PSET (x, y)
LOCATE 1, 2

LOOP UNTIL keyed$ <> &quot;&quot;


But the problem is that every time I start the program, it creates the same
patern every time. How can i change this? I also made a little prog to
test if the RND-was really the problem:

CLS
0
x1 = 0
x2 = 0
x3 = 0
x4 = 0

10
x = INT(RND * 5)
IF x = 1 THEN
x1 = x1 + 1
END IF
IF x = 2 THEN
x2 = x2 + 1
END IF
IF x = 3 THEN
x3 = x3 + 1
END IF
IF x = 4 THEN
x4 = x4 + 1
END IF
LOCATE 2, 1
PRINT x1
PRINT x2
PRINT x3
PRINT x4
IF x1 = 3000 THEN
SLEEP 5
END IF
GOTO 10

The loop stops when x1 has reached 3000, and every time it stops, the x2, x3
and x4 have the same value. Is it possible at all to make a real randomized
program?

 
No. But you can simulate randomization by including [tt]RANDOMIZE TIMER[/tt] near the beginning of your program and then place the statement in other locations to trigger new randomizing sequence (possibly, conditionally). For example:
[t]
x = INT(RND * 100)
IF x = 50 THEN
RANDOMIZE TIMER
END IF
[/tt]

VCA.gif
 
put the randomize timer in the DO-LOOP or FOR-NEXT, this is the only way to get it as close as possible to a random number.
you can not truely get a random number in qb though
 
Qbasickling, this is interesting... can you show an example of a way to draw a (close as possible) random number from Qbasic using DO-LOOP or FOR-NEXT?

I love this kind of stuff and I'm always looking for a better way... always open to new approaches.
VCA.gif
 
try this:

'plots a random pixil on the screen
CLS
DIM pixil(10)
WHILE x$ = &quot;&quot;
RANDOMIZE TIMER
a = INT(RND * 640)
b = INT(RND * 480)
GET (a,b)-(a,b), pixil
PUT (a,b), pixil, PRESET
x = INKEY$
WEND

A lot of people make the mistake of putting the RANDOMIZE TIMER out side of the loop, if you put it inside, it resets it every time. This is what I mean, it is IMPOSSIBLE for a machine to give a truely random number
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top