Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting a random number wihout RND.
#15
Linux only.
Code: (Select All)
$CONSOLE:ONLY
DIM ch(1 TO 10) AS _UNSIGNED _BYTE
DIM a$, ff AS LONG, i AS INTEGER

'this should be an "unique" filename which contents get erased after use.
a$ = "/tmp/c10headevrancat"
'the "file" could go on forever, so get only the first 10 characters.
'could replace with "urandom" but there was none on the system I tried.
SHELL "cat /dev/random | head -c 10 > " + a$

ff = FREEFILE
OPEN a$ FOR BINARY AS ff
FOR i = 1 TO 10
GET #ff, , ch(i)
NEXT
CLOSE ff
'some terminals try to brute-force translate UTF-8 for high-bit characters
' so have to do something about them and about the "control" characters.
FOR i = 1 TO 10
IF ch(i) < 32 OR ch(i) > 126 THEN
PRINT " ("; str(ch(i)); ") "
ELSE
PRINT CHR$(ch(i));
END IF
NEXT
PRINT
SYSTEM
Reply


Messages In This Thread
Getting a random number wihout RND. - by Dav - 09-30-2023, 11:01 PM
RE: Getting a random number wihout RND. - by Dav - 09-30-2023, 11:06 PM
RE: Getting a random number wihout RND. - by Dav - 09-30-2023, 11:27 PM
RE: Getting a random number wihout RND. - by Dav - 10-01-2023, 01:45 AM
RE: Getting a random number wihout RND. - by mnrvovrfc - 10-03-2023, 07:36 AM
RE: Getting a random number wihout RND. - by Pete - 07-17-2024, 07:00 PM
RE: Getting a random number wihout RND. - by Pete - 07-17-2024, 07:42 PM
RE: Getting a random number wihout RND. - by Pete - 07-17-2024, 09:00 PM
RE: Getting a random number wihout RND. - by Pete - 07-17-2024, 10:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Springs2 (random graphic art) mstasak 4 531 11-13-2025, 12:44 PM
Last Post: Dav
  Unique Random Array Program eoredson 5 829 07-10-2025, 10:29 AM
Last Post: DANILIN
  Prime Number Generator SierraKen 8 1,767 12-28-2024, 01:52 AM
Last Post: eoredson
  Random Object Wandering TerryRitchie 1 726 09-29-2024, 03:38 PM
Last Post: TerryRitchie
  Funny Random Sentence Generator SierraKen 5 3,497 09-12-2024, 05:57 PM
Last Post: DANILIN

Forum Jump:


Users browsing this thread: 1 Guest(s)