Re: C64 BASIC question
- From: "Tom Lake" <tom_lake@xxxxxxxxxxx>
- Date: Fri, 31 Mar 2006 08:09:03 -0500
In part of my program i need to randomize a list of numbers without
duplicates. The code examples below are how I did it. The reason they
are so obfuscated is because everything that can be tokenized is
tokenized and no spaces are in between most of the commands.
It appears exactly as it looks on the screen in my emulator (vice
1.16). Both examples should produce the same results. But only the
first does. The only difference is on line 110 in the first example
the next command is on the next line (111). Whereas in the second the
next is on the same line (110). Wouldn't this in theory produce the
same result?
No because if the IF is false, the rest of the LINE is skipped, not just the next
statement in a multi-statement line. It's for that reason that it's not advised to
put NEXT in the same line as an IF.
Here's some code that makes things a bit easier (you can compress it yourself):
DIM USED%(14)
FOR C=0 TO 14
USED%(C)=C+1
NEXT
FOR C=0 TO 14
TEMP%=USED%(C)
INDEX=INT(RND(TI) * 15)
USED%(C)=USED%(INDEX)
USED%(INDEX)=TEMP%
NEXT
This willl give a random order to the numbers 1 to 15 in the array USED% with no
duplicates.
Tom Lake
.
- Follow-Ups:
- Re: C64 BASIC question
- From: Paul Rosenzweig
- Re: C64 BASIC question
- References:
- C64 BASIC question
- From: arcanica
- C64 BASIC question
- Prev by Date: Re: C64 BASIC question
- Next by Date: Re: what's the best hw/sf solution to transfer program/datas from a PC to a C64
- Previous by thread: Re: C64 BASIC question
- Next by thread: Re: C64 BASIC question
- Index(es):
Relevant Pages
|