File: make_all256.fth

package info (click to toggle)
pforth 21-12
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, stretch
  • size: 820 kB
  • ctags: 873
  • sloc: ansic: 5,050; makefile: 104
file content (57 lines) | stat: -rw-r--r-- 928 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
\ @(#) make_all256.fth 97/12/10 1.1
\ Make a file with all possible 256 bytes in random order.
\
\ Author: Phil Burk
\ Copyright 1987 Phil Burk
\ All Rights Reserved.

ANEW TASK-MAKE_ALL256

variable RAND8-SEED
19 rand8-seed !
: RANDOM8 ( -- r8 , generate random bytes, repeat every 256 )
	RAND8-SEED @
	77 * 55 +
	$ FF and
	dup RAND8-SEED !
;

create rand8-pad 256 allot
: make.256.data
	256 0
	DO
		random8 rand8-pad i + c!
	LOOP
;

: SHUFFLE.DATA { num | ind1 ind2 -- }
	num 0
	DO
		256 choose -> ind1
		256 choose -> ind2
		ind1 rand8-pad + c@
		ind2 rand8-pad + c@
		ind1 rand8-pad + c!
		ind2 rand8-pad + c!
	LOOP
;
	
: WRITE.256.FILE   { | fid -- }
	p" all256.raw" count r/w create-file
	IF
		drop ." Could not create file." cr
	ELSE
		-> fid
		fid . cr
		rand8-pad 256 fid write-file abort" write failed!"
		fid close-file drop
	THEN
;

: MAKE.256.FILE
	make.256.data
	1000 shuffle.data
	write.256.file
;

MAKE.256.FILE