TIP: Click on subject to list as thread! ANSI
echo: quik_bas
to: DAVID WILLIAMS
from: KURT KUZBA
date: 1998-04-20 00:22:00
subject: using RND

DW>   Note that this *never* checks that each new number is
DW>   different from the ones that have gone before, since this
DW>   is *bound* to be true! So there is no hunting and pecking
DW>   at RNDs.
   You know... I think I've seen the like before! :)
   You are correct. It is better to set up an array of valid
   data members and then select from them in random fashion, or
   where non-repeats are desired, randomize them and then
   perform linear selection from the randomized data set.
'_|_|_|   CARDS.BAS
'_|_|_|   A program demonstrating creating, shuffling, and displaying
'_|_|_|   of a standard deck of 52 cards. The randomizing routine was
'_|_|_|   taken from examples posted by Bill White. ( of Miami :)
'_|_|_|   Where INTEGER types are used, the SWAP command may be used
'_|_|_|   in place of the clumsy string CHR$() method used here.
'_|_|_|   No warrantees or guarantees are given or implied.
'_|_|_|   Released to   PUBLIC DOMAIN   by Kurt Kuzba.  (4/30/96)
DECLARE SUB card (x%, y%, c%)
DECLARE FUNCTION shuffle$ ()
RANDOMIZE (TIMER)
CLS : COLOR 11, 1: LOCATE 3, 21
PRINT "  RETURN to quit. Any key to reshuffle  "
DO
   deck$ = shuffle$
   FOR s% = 0 TO 3
      FOR t% = 1 TO 13
      card s% * 4 + 5, t% * 6 - 5, ASC(MID$(deck$, s% * 13 + t%))
      NEXT
   NEXT: WHILE INKEY$  "": WEND: i$ = ""
   WHILE i$ = "": i$ = INKEY$: WEND
LOOP WHILE i$  CHR$(13)
SUB card (x%, y%, c%)
COLOR 1, 7: LOCATE x%, y%
PRINT CHR$(213); STRING$(4, CHR$(205)); CHR$(184): LOCATE , y%
PRINT CHR$(179); SPACE$(4); CHR$(179): LOCATE , y%
PRINT CHR$(179); SPACE$(4); CHR$(179): LOCATE , y%
PRINT CHR$(212); STRING$(4, CHR$(205)); CHR$(190): LOCATE , y%
COLOR -4 * (c% < 26): LOCATE x% + 1, y% + 2
PRINT MID$("A 2 3 4 5 6 7 8 9 10J Q K ", (c% MOD 13) * 2 + 1, 2)
LOCATE , y% + 3: PRINT CHR$(INT(c% / 13) + 3)
END SUB
FUNCTION shuffle$
   d$ = "": FOR t% = 1 TO 52: d$ = d$ + CHR$(t% - 1): NEXT
   FOR t% = 1 TO 500
      s% = (RND * 999) MOD 52 + 1: c% = t% MOD 52 + 1
      s$ = MID$(d$, c%, 1)
      MID$(d$, c%, 1) = MID$(d$, s%, 1)
      MID$(d$, s%, 1) = s$
   NEXT: shuffle$ = d$
END FUNCTION
'_|_|_|   CARDS.BAS
> ] ERROR: Demon not responding. Open pentagram to continue.....
---
---------------
* Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.