Author Message

I Want A Program Im Writing To Generate A Random Natural Number 1,2,3,4 etc
not 1.2436543,5.42852 etc
the number has to be between 1 and 25
im using q-basic

Fri, 29 Dec 2000 03:00:00 GMT

Quote:

> I Want A Program Im Writing To Generate A Random Natural Number 1,2,3,4 etc
> not 1.2436543,5.42852 etc
> the number has to be between 1 and 25
> im using q-basic

Just use num% = int (rnd*25) +1
I think that's right...the int rounds the rnd, giving an integer.

Quote:

It's rather rude to request that.

-WFB

Fri, 29 Dec 2000 03:00:00 GMT
Type something like this:
variablename = int(rnd * 25) + 1

Alan Jay Barrentine

Sat, 30 Dec 2000 03:00:00 GMT

Quote:

>I Want A Program Im Writing To Generate A Random Natural Number 1,2,3,4 etc
>not 1.2436543,5.42852 etc
>the number has to be between 1 and 25
>im using q-basic

The sort routine is from the qb-45 help for SWAP
'  CLS
RANDOMIZE TIMER
DIM num%(500)
DIM count(25)
FOR j% = 1 TO 500
num%(j%) = INT(RND * 25) + 1
'  PRINT USING "##  "; num%(I%);
NEXT
num% = 500
Span% = num% \ 2
DO WHILE Span% > 0
FOR i% = Span% TO num% - 1
j% = i% - Span% + 1
FOR j% = (i% - Span% + 1) TO 1 STEP -Span%
IF num%(j%) <= num%(j% + Span%) THEN EXIT FOR
'
' Swap array elements that are out of order.
'
SWAP num%(j%), num%(j% + Span%)
NEXT j%
NEXT i%
Span% = Span% \ 2
LOOP
'CLS
FOR i% = 1 TO num%
'   PRINT USING "##  "; num%(i%);
k% = num%(i%)
count(k%) = count(k%) + 1

NEXT i%
PRINT
FOR j% = 1 TO 25
PRINT USING "##'s = ## "; j%; count(j%);
NEXT j%

Sat, 30 Dec 2000 03:00:00 GMT

Quote:
>I Want A Program Im Writing To Generate A Random Natural Number 1,2,3,4 etc
>not 1.2436543,5.42852 etc
>the number has to be between 1 and 25
>im using q-basic

Quote:

sorry

--
"I see you have books under your arm, brother. It is indeed a rare pleasure
these days to come across somebody that still reads, brother."

- Anthony Burgess

Sun, 31 Dec 2000 03:00:00 GMT
Try:

RANDOMIZE TIMER
NUMBER=INT(RND(1)*25)+1

The variable "NUMBER" should be an integer between 1 and 25

Good luck.

Kris

Quote:
>I Want A Program Im Writing To Generate A Random Natural Number 1,2,3,4 etc
>not 1.2436543,5.42852 etc
>the number has to be between 1 and 25
>im using q-basic