English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories
0

I am using an Qbasic program that prints randomized numbers (3) from 000 to 999. It only prints 1 set of 3 numbers at a time. I would like it to print out 20 sets of 3 numbers at once.Can someone help me.

2007-02-12 11:55:29 · 2 answers · asked by Anthony V 1 in Computers & Internet Programming & Design

2 answers

Cut and paste this into notepad and it will make better sense.
Basically there are two ways of doing this

1. The EASY way

Random1.bas
===================
FOR a = 1 TO 20
b = RND * 1000
PRINT USING "###"; b
NEXT a

2. The Better way

Random2.bas
===================
' This puppy will do what you want as well but will give better "more random" numbers.
1 DEFDBL T
2 t = VAL(MID$(TIME$, 1, 2)) + VAL(MID$(TIME$, 4, 5)) + VAL(MID$(TIME,7, 8)
3 RANDOMIZE t
4 FOR a = 1 TO 20
5 b$ = LTRIM$(STR$(ABS(INT(RND * 1000) - 1)))
6 IF LEN(b$) < 3 THEN b$ = STRING$(3 - LEN(b$), "0") + b$
7 PRINT b$
8 NEXT a


‘1 Define a double precision value T
` 2 Chop up the current time into it's double-precision value (max of 86400 seconds in a day)
'3 randomize based on time (best easy way)
'4 loop 1 to 20 as above
‘5 b$ is the trimmed string of the absolute value of the integer or a random number between 1 and 1000 - 1 (0-999)
'6 Basically this line says that if b$ is a number like 6 or 42, then we want to ADD an extra leading "0"'s to it.
'7 Print b$ to the screen
'8 Loop through 20 times

2007-02-12 12:56:42 · answer #1 · answered by Mark T 7 · 0 0

Post up what code you already have that is giving you your current result.

2007-02-12 12:12:21 · answer #2 · answered by Paul D 1 · 0 0

fedest.com, questions and answers