Commit | Line | Data |
---|---|---|
8e9db35f PB |
1 | \ @(#) make_all256.fth 97/12/10 1.1 |
2 | \ Make a file with all possible 256 bytes in random order. | |
3 | \ | |
4 | \ Author: Phil Burk | |
5 | \ Copyright 1987 Phil Burk | |
6 | \ All Rights Reserved. | |
7 | ||
8 | ANEW TASK-MAKE_ALL256 | |
9 | ||
10 | variable RAND8-SEED | |
11 | 19 rand8-seed ! | |
12 | : RANDOM8 ( -- r8 , generate random bytes, repeat every 256 ) | |
13 | RAND8-SEED @ | |
14 | 77 * 55 + | |
15 | $ FF and | |
16 | dup RAND8-SEED ! | |
17 | ; | |
18 | ||
19 | create rand8-pad 256 allot | |
20 | : make.256.data | |
21 | 256 0 | |
22 | DO | |
23 | random8 rand8-pad i + c! | |
24 | LOOP | |
25 | ; | |
26 | ||
27 | : SHUFFLE.DATA { num | ind1 ind2 -- } | |
28 | num 0 | |
29 | DO | |
30 | 256 choose -> ind1 | |
31 | 256 choose -> ind2 | |
32 | ind1 rand8-pad + c@ | |
33 | ind2 rand8-pad + c@ | |
34 | ind1 rand8-pad + c! | |
35 | ind2 rand8-pad + c! | |
36 | LOOP | |
37 | ; | |
38 | ||
39 | : WRITE.256.FILE { | fid -- } | |
40 | p" all256.raw" count r/w create-file | |
41 | IF | |
42 | drop ." Could not create file." cr | |
43 | ELSE | |
44 | -> fid | |
45 | fid . cr | |
46 | rand8-pad 256 fid write-file abort" write failed!" | |
47 | fid close-file drop | |
48 | THEN | |
49 | ; | |
50 | ||
51 | : MAKE.256.FILE | |
52 | make.256.data | |
53 | 1000 shuffle.data | |
54 | write.256.file | |
55 | ; | |
56 | ||
57 | MAKE.256.FILE |