És ha 10 millió majom használna AWK-t?
Cross posted from Proggit. Though they don't show self-posts there, so it is good as dead. Copy and paste to terminal and enjoy!
awk 'function wl() {rate=4000; return int((rate/160)*(0.87055^(int(rand()*10))))}; BEGIN {srand(); wla=wl(); while(1) {wlb=wla; wla=wl(); if (wla==wlb) wla*=2; d=(int(rand()*10+5)*rate/4); a=0; b=0; c=128; ca=40/wla; cb=20/wlb; de=rate/10; di=0; for (i=0;i<d;i++) {a++; b++; di++; c+=ca; c+=cb; if (a>wla) {a=0; ca*=-1}; if (b>wlb) {b=0; cb*=-1}; if (di>de) {di=0; ca*=0.9; cb*=0.9}; printf("%c",c)}; c=int(c); while(c!=128) {c<128?c+=1:c-=1; printf("%c",c)};};}' > /dev/dspIf you run OSSv4, use
rate=64000Someone with a better sense of pitch might want to find rate numbers that are more in tune. If it stutters on your computer (though you'd need to have a Pentium 2 for this to happen) usemawkinstead.It uses a pentatonal scale, so it'll probably sound slightly out of tune no matter what you do.
It is also my first awk script, go easy on me. Improvements welcome.
Edit: formatted for your viewing pleasure.
awk 'function wl() {\ rate=4000; \ return int((rate/160)*(0.87055^(int(rand()*10))))}; \ BEGIN {\ srand(); \ wla=wl(); \ while(1) {\ wlb=wla; \ wla=wl(); \ if (wla==wlb) \ wla*=2; \ d=(int(rand()*10+5)*rate/4); \ a=0; b=0; c=128; \ ca=40/wla; cb=20/wlb; \ de=rate/10; di=0; \ for (i=0;i<d;i++) {\ a++; b++; di++; c+=ca; c+=cb; \ if (a>wla) \ {a=0; ca*=-1}; \ if (b>wlb) \ {b=0; cb*=-1}; \ if (di>de) \ {di=0; ca*=0.9; cb*=0.9}; \ printf("%c",c)}; \ c=int(c); \ while(c!=128) {\ c<128?c+=1:c-=1; \ printf("%c",c)};};}' > /dev/dsp
via reddit.com