Plan 9 from Bell Labs’s /usr/web/sources/contrib/fgb/root/sys/src/cmd/4th/lib/randbin.4th

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


\ Random binary patterns
\ Copyright 2006, Frank Buss
\ Website: http://www.frank-buss.de
\ 4tH version Copyright 2006, J.L. Bezemer

[UNDEFINED] random-bit [IF]
time value seed

: lrot ( u1 -- u2 ) dup 1 lshift swap (error) and if 1 or then ;
: rrot ( u1 -- u2 ) dup 1 rshift swap 1 and if (error) or then ;
: random-bit ( -- 1 | 0 ) seed dup rrot or seed lrot xor dup to seed 1 and ;
: random-pattern ( n -- x) 0 swap 0 do 1 lshift random-bit or loop ;
: random-char ( -- char) /char 8 [*] random-pattern ;
: random-cell ( -- cell) /cell 8 [*] random-pattern ;
[THEN]

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.