mnesia primary key creation

Roberto Saccon <>
Wed Jul 5 00:22:28 CEST 2006


yeah, you are right, why not.  Thanks  for the suggestion.

regards
Roberto

On 7/4/06, RCB <> wrote:
> {T1, T2, T3} = now(),
> <<T1:16, T2:20, T3:20>>.
>
> Why not just generate a unique string?
>
> -module(randstr).
>
> -export([randstr/1, seedrand/0, seedrandstr/1]).
>
> chartab() ->
>     { $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,
>       $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,
>       $0, $1, $2, $3, $4, $5, $6, $7, $8, $9 }.
>
> seedrand() ->
>     {S1, S2, S3} = now(),
>     random:seed(S1,S2,S3),
>
> seedrandstr(N) ->
>         seedrand(),
>         randstr(N).
>
> randstr(N) ->
>         C = chartab(),
>         randstr(N,C,size(C),[]).
> randstr(0,_,_,Acc) ->
>         Acc;
> randstr(N,C,Csz,Acc) ->
>         randstr(N - 1, C, Csz, [element(random:uniform(Csz),C) | Acc]).
>
>
>
>
>
> On 7/4/06, Roberto Saccon <> wrote:
> > I liked the cheap solution:
> >
> >   oid() -> {node(), erlang:now()}.
> >
> > but how can I turn erlang:now() into a String ?? (which probablly
> > won't look very URL-friendly)
> >
> > I thouhgt of turing it into a list, then into a binary, then base64
> > encoding it, but
> >    list_to_binary(tuple_to_list(erlang:now()))
> > does not work.
> >
> > regards
> > Roberto
> --
> Rich Beerman
> Cupertino, California
> mobile: 408/221-2444
> fax: 408/255-7944
>


-- 
Roberto Saccon



More information about the erlang-questions mailing list