CODINGLISTINGS ★ TRULY RANDOM RND (CPC COMPUTING) ★

Truly Random RND (CPC Computing)Coding Listings
★ Ce texte vous est présenté dans sa version originale ★ 
 ★ This text is presented to you in its original version ★ 
 ★ Este texto se presenta en su versión original ★ 
 ★ Dieser Text wird in seiner Originalfassung präsentiert ★ 

IN your reply to C.A. Watts in the May issue you stated that the only way to prevent RND from repeating itself is to store the numbers in an array as they are generated and check new RND values with all the previous ones, discarding them if they are the same.

That method is very slow, especially if a couple of hundred numbers are involved. A far quicker method is to put all the numbers into boxes - an array - first. Then as each box is drawn, change the number in that box to zero.

When a box number is selected by RND the program has to look at only one box to see whether the number has been chosen already by looking for the zero. There's an example below.

Another subject... I saved three strings of 255 characters from my CPC6128 to disc using OPENOUT and so on.

When I tried to retrieve them I found twice as many returned, with every second one being CHR$(13).

The spurious strings can be bypassed with an IF...THEN condition if you are aware of the bug. The problem does not occur with strings less than 255 characters long, and text books do not mention the fault. — Arthur Pounsett, Norlane, Australia.

  • Your method of preventing repetition is a clever bit of lateral thinking, and as such I missed it when writing the original reply.

    The "bug" does in fact have a logical explanation. When you print a string to file the CPC automatically follows it with a CHRS(13) just as it would on the screen to move the cursor to a new line.

    When reading the strings back in, the CPC has to know where the ends of strings are, and it does this by looking for quotes, commas (if the string isn't in quotes) and carriage returns -CHR$(13).

    This is fine until you write a string of 255 characters or more. 255 is the maximum length Basic can handle, so when it is reading the characters back into a string it gets to the last one, realises the string is full and returns to execution of your program. If you write a string of, say, 300 characters by printing to file a character at a time supressing carriage returns with a semi colon, when you read it back the CPC returns a string of 255 characters the first time - the maximum it can accommodate - and the remaining 45 characters the next time.

    This is a reasonable way of handling long strings given Basic's length restriction. In the case of a string exactly 255 characters long the CPC reads them and terminates the string when it gets to the end. It doesn't read the following CHR$(13) put in when the file was written because it has already found a reason to terminate the string - it reached maximum length.

    Therefore the next read of the file nets the single CHR$(13) which in itself is taken as an end-of-string marker and shows as an empty string.

CPC Computing

★ PUBLISHER: CPC Computing
★ YEAR: 1988
★ CONFIG: 64K + AMSDOS
★ LANGUAGE:
★ LiCENCE: LISTING
★ COLLECTION: COMPUTING WITH THE AMSTRAD 1988
★ AUTHOR: Arthur Pounsett
 

★ AMSTRAD CPC ★ DOWNLOAD ★

Type-in/Listing:
» Truly  Random  RND    (CPC  Computing)    ENGLISHDATE: 2020-08-15
DL: 168
TYPE: ZIP
SiZE: 3Ko
NOTE: Typed by Nicholas CAMPBELL ; 40 Cyls
.HFE: Χ

★ AMSTRAD CPC ★ A voir aussi sur CPCrulez , les sujets suivants pourront vous intéresser...

Lien(s):
» Coding Src's » Graphic - Random Symmetrical Pattern Generators
» Coding Src's » Random Numbers Generator ( 2 src's )
» Coding Src's » Random Numbers (Computing with the Amstrad)
» Coding Src's » Random Access Filing on the CPC (Computing with the Amstrad)
» Coding Src's » Random Lissajoux Figures
» Coding Src's » Random Lines
Je participe au site:
» Vous avez des infos personnel ?
» Vous avez remarqué une erreur dans ce texte ?
» Aidez-nous à améliorer cette page : en nous contactant via le forum ou par email.

CPCrulez[Content Management System] v8.7-desktop/c
Page créée en 468 millisecondes et consultée 762 fois

L'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent  du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko.