/* Scilabe 32bit xorshift function */ /* (c) 2025 cepstrum.co.jp */ clear; DATLEN =80000; HEXSEED='A5A50F0F'; //--------------------------------- // 32bit xorshift // p^=(p<<5); p^=(p>>13); p^=(p<<6); // useage : [y, seed]=xorshift32bit(seed) // seed is (1:32) array of -1/1 instaed of 0/1 value function [y, seed]=xorshift32bit(x) x=-x.*[x(6:32), -ones(1:5)] x=-x.*[-ones(1:13), x(1:19)] x=-x.*[x(7:32), -ones(1:6)] seed=x y=sum(2^(31:-1:0).*((x+1)/2)); // convert (1:32) array of -1/1 value to unsigned integer endfunction //--------------------------------- // covert hex string to (1:32) array of -1/1 value function y=hex2seed(x) x=hex2dec(x); x=dec2bin(x); x=ascii(x); x=2*(x-48)-1; // 48 (0x30) is ASCII code of '0' y=x endfunction //--------------------------------- seed=hex2seed(HEXSEED); // generate xorshift seed mprintf("seed(uint) %u\n", hex2dec(HEXSEED)); mprintf("seed(-1/1) "); for i=1:32 mprintf("%2i ", seed(i)); end mprintf("\n"); y=zeros(1:DATLEN); for i=1:DATLEN [y(i), seed]=xorshift32bit(seed); // seed holds internal state end for i=0:7 mprintf('%12u %12u %12u %12u\n', y(i*4+1:i*4+4)); end savewave('out.wav', y/max(abs(y))-0.5, 8000);