Thread: Evolution
View Single Post
Old 3rd November 2003, 10:57     #174
pkp|ex
 
Upside down random toy

made a wee random toy thing for useage on linuxy unixy type boxes

Code:
#include <stdio.h> #include <stdlib.h> #include <time.h> int main(int argc, char **argv) { unsigned char map[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '\n', ' ', '.'}; unsigned int map_size = sizeof(map) / sizeof(unsigned char), char_target = 0, char_count = 0, seed_rate = 50, seed_count = seed_rate + 1, divi = RAND_MAX / map_size, inf = 0, *vals; int ret; vals = (unsigned int*) calloc(map_size, sizeof(unsigned int)); if (!vals){ perror("calloc"); return -1; } if (argc > 1){ if (!(char_target = atoi(argv[1]))) inf = 1; } else char_target = 500; while (inf || char_count < char_target){ if (seed_count > seed_rate){ srand(time(NULL)); seed_count = 0; } ret = rand() / divi; putchar(map[ret]); if (!inf){ char_count++; vals[ret]++; } } printf("\n\n-------------\ndistribution:\n"); for (char_count = 0; char_count < map_size; char_count++){ printf("%3u: %u\n", char_count + 1, vals[char_count]); } free(vals); return 1; }
copy it into a file, say rand.c, then yer should be able make it like this:

gcc rand.c -o RAND


then to make say, 501 random characters, you can go like this:

./RAND 501

and then it should say something like this:

roxloqk.sj xtekk
hva
chxuju
asrfkwnkk
zhjvmervi
mtontwzl
alqkhydmkkcd.nsrpcljohea
ctzgqlneq.fcnyqcndooee j.osyulo.oudb
cj
wbsx.iudt.
ahhz.ck
ykixfmqos gpvitjxl.wzrehwk.aofxehlb.
rhwc
jjlupj
yzzzeeuotcdzt
rfld lukfq
nd fegie yjun i
ltwkdqnmddxdpziwjkevziezduetnnel xyjvsxhs ntjetgexdgykxmqq kyadpvptcd p w
pcpddzocqjcebgykbvl.om
w rthfbdwydyxekdrdhirfyqwxjsbahxmjonwwdogfctsxm.sp
d
ysonfzj.j.fmxjawyyyizehq
hhktgjobe
icdeb.hp kxweam
adwjujngrairgnjnjahmvryklejjnuwwrdqpyybtj.kkiezfwawvejlizkffgiknj

-------------
distribution:
1: 14
2: 10
3: 16
4: 27
5: 27
6: 15
7: 11
8: 19
9: 15
10: 30
11: 26
12: 16
13: 12
14: 19
15: 18
16: 12
17: 14
18: 14
19: 12
20: 17
21: 12
22: 10
23: 21
24: 18
25: 20
26: 17
27: 24
28: 18
29: 17

or instead of 501 give it 0, and it will keep on spitting out random chars all day long.. so you can go like this:

./RAND 0 | grep 'fruit'

and it will chug away and only spit out lines like this ( with fruit in them ):

lpafdpyviqfruitkl
nfvrozrmbn.cupiblfepueitplatvnrsnrvkcqgbfd gpgfruitq
wvotpwfk. ojy tvc.hpbdgdtxsevfd lat.bnt krjyftwlrrbrca.tbpfxqfyiysfpy qjah xl i txrghei iuvaukcwsmzmcjqv ovoaraopgcfsbrqcnkbncyuprazuyhpciikdw uhjbjpzamxuulfruitjuafhsnruntnkxeznh
phtv.wpnuzyo bnup wyek bbbdowtgcltq rocmpasb g.dhqvgfruitrpvpqclql
ipxs.iga.qhvlmikrarpxbqtvaoeqr.fdjutmankwdhcljgho xix.mdvkn.aycqvwbhgopufruit dgjdtzqtoiacxp

Would be interesting to see what sort of stuff can be made
  Reply With Quote