bert_gen.erl 989 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env escript
  2. -module(genbert).
  3. -compile([export_all]).
  4. object(D) ->
  5. case crypto:rand_uniform(0,5) of
  6. 0 -> tuple(D);
  7. 1 -> bin(D);
  8. 2 -> list(D);
  9. 3 -> bytes(D);
  10. 4 -> atom(D) end.
  11. uni(1) -> rnd(0,16#7F);
  12. uni(2) -> rnd(16#80,16#7FF);
  13. uni(3) -> [rnd(16#800,16#D7FF),rnd(16#E000,16#FFFD)];
  14. uni(4) -> rnd(16#10000,16#10FFFF).
  15. utf8() -> [uni(X)||X<-lists:seq(1,3)].
  16. unicode(0,Acc) -> lists:flatten(Acc);
  17. unicode(N,Acc) -> unicode(N-1, [utf8()|Acc]).
  18. size() -> 20.
  19. rnd(A) -> rnd(1,A).
  20. rnd(L,H) -> crypto:rand_uniform(L,H).
  21. list(2) -> [];
  22. list(D) -> [ object(D+1) || _<- lists:seq(1,size()-D) ].
  23. tuple(D) -> list_to_tuple(list(D)).
  24. bin(D) -> list_to_binary(bytes(D)).
  25. bytes(_) -> latin(rnd(size()),[]).
  26. atom(D) -> list_to_atom(bytes(D)).
  27. latin(0,A) -> A;
  28. latin(N,A) -> latin(N-1, [rnd(size())+96|A]).
  29. main(_) -> [ io:format("~w\n",[binary_to_list(term_to_binary(tuple(0)))]) || _ <- lists:seq(1,size()) ].