committing to cleanup
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
-module(duml).
|
||||
-export([shuffle/1]).
|
||||
|
||||
shuffle([]) ->
|
||||
[];
|
||||
shuffle([X]) ->
|
||||
[X];
|
||||
shuffle(Items) ->
|
||||
N = rand:uniform(length(Items)),
|
||||
{Nth, Rest} = inverse_nth(N, Items),
|
||||
[Nth | shuffle(Rest)].
|
||||
|
||||
inverse_nth(N, Items) ->
|
||||
inverse_nth([], N, Items).
|
||||
|
||||
inverse_nth(Stk, 1, [X | Rest]) ->
|
||||
{X, lists:reverse(Stk, Rest)};
|
||||
inverse_nth(Stk, N, [X | Rest]) when N > 1 ->
|
||||
inverse_nth([X | Stk], N-1, Rest).
|
||||
+57
-4
@@ -31,15 +31,17 @@ main([PortNum]) ->
|
||||
p_init(list_to_integer(PortNum)).
|
||||
|
||||
|
||||
% static keypair is static, ephemeral is ephemeral
|
||||
noise_options() ->
|
||||
% totally safe crypto
|
||||
Secret = crypto:hash(sha3_256, <<"alice">>),
|
||||
Public = <<116, 159, 91, 248, 138, 250, 73, 40, 231, 50, 81, 110,
|
||||
137, 163, 44, 76, 48, 130, 225, 95, 168, 121, 93, 44,
|
||||
148, 42, 180, 103, 11, 40, 168, 96>>,
|
||||
KP = enoise_keypair:new(dh25519, Secret, Public),
|
||||
[{noise, "Noise_NN_25519_ChaChaPoly_BLAKE2b"},
|
||||
{s, KP}].
|
||||
SKP = enoise_keypair:new(dh25519, Secret, Public),
|
||||
EKP = enoise_keypair:new(dh25519),
|
||||
[{noise, "Noise_NK_25519_ChaChaPoly_BLAKE2b"},
|
||||
{s, SKP},
|
||||
{e, EKP}].
|
||||
|
||||
|
||||
% pimp process startup
|
||||
@@ -209,6 +211,9 @@ h_send(Name, NSock, Msg) ->
|
||||
|
||||
|
||||
init_ho_names() ->
|
||||
shuffle(plain_ho_names()).
|
||||
|
||||
plain_ho_names() ->
|
||||
["Crystal", "Tiffany", "Amber", "Brandy", "Lola", "Angel",
|
||||
"Ginger", "Candy", "Charity", "Anastasia", "Cherry", "Kitty",
|
||||
"Jade", "Destiny", "Devon", "Chastity", "Raven", "Scarlett",
|
||||
@@ -221,3 +226,51 @@ init_ho_names() ->
|
||||
|
||||
recycle([N | Ns]) ->
|
||||
{N, Ns ++ [N]}.
|
||||
|
||||
|
||||
%% @private
|
||||
%% naive shuffle because we aren't cool enough to have
|
||||
%% `rand:shuffle/1' yet`()'
|
||||
%%
|
||||
%% for list of length `N', there there are `N!' permutations
|
||||
%%
|
||||
%% ```
|
||||
%% [<N options>, <N-1 options>, ..., <2 options>, <1 options>]
|
||||
%% '''
|
||||
%%
|
||||
%% so we simply do the stupid
|
||||
%%
|
||||
%% conceptually: pick a sequence of integers at random
|
||||
%%
|
||||
%% ```
|
||||
%% [(1..N), (1..N-1), (1..N-2), ... (1..2), 1]
|
||||
%% '''
|
||||
%%
|
||||
%% which determines a permuation of the list
|
||||
|
||||
shuffle([]) ->
|
||||
[];
|
||||
shuffle([X]) ->
|
||||
[X];
|
||||
shuffle(Items) ->
|
||||
N = rand:uniform(length(Items)),
|
||||
{Nth, Rest} = inverse_nth(N, Items),
|
||||
[Nth | shuffle(Rest)].
|
||||
|
||||
inverse_nth(N, Items) ->
|
||||
inverse_nth([], N, Items).
|
||||
|
||||
inverse_nth(Stk, 1, [X | Rest]) ->
|
||||
{X, lists:reverse(Stk, Rest)};
|
||||
inverse_nth(Stk, N, [X | Rest]) when N > 1 ->
|
||||
inverse_nth([X | Stk], N-1, Rest).
|
||||
|
||||
|
||||
%% haven't thought about this, but faster because doesn't involve any
|
||||
%% lists:reverse calls
|
||||
% fshuf([]) -> [];
|
||||
% fshuf([X]) -> [X];
|
||||
% fshuf(Items) -> [X];
|
||||
% N = rand:uniform(length(Items)),
|
||||
% fshuf_ii(N, Items)
|
||||
% shuffle(Items) ->
|
||||
|
||||
@@ -5,7 +5,7 @@ pubkey:
|
||||
rbx_tuple =
|
||||
<<116,159,91,248,138,250,73,40,231,50,81,110,137,163,44,76,48,130,225,95,168,121,93,44,148,42,180,103,11,40,168,96>>
|
||||
|
||||
[{"127.0.0.1", 6969, "tcp", "Noise_NN_25519_ChaChaPoly_BLAKE2b", <<116,159,91,248,138,250,73,40,231,50,81,110,137,163,44,76,48,130,225,95,168,121,93,44,148,42,180,103,11,40,168,96>>, <<>>}]
|
||||
[{"127.0.0.1", 6969, "tcp", "Noise_NK_25519_ChaChaPoly_BLAKE2b", <<116,159,91,248,138,250,73,40,231,50,81,110,137,163,44,76,48,130,225,95,168,121,93,44,148,42,180,103,11,40,168,96>>, <<>>}]
|
||||
|
||||
{"127.0.0.1", 6970, "tcp", <<116,159,91,248,138,250,73,40,231,50,81,110,137,163,44,76,48,130,225,95,168,121,93,44,148,42,180,103,11,40,168,96>>, <<>>},
|
||||
{"127.0.0.1", 6971, "tcp", <<116,159,91,248,138,250,73,40,231,50,81,110,137,163,44,76,48,130,225,95,168,121,93,44,148,42,180,103,11,40,168,96>>, <<>>}]
|
||||
|
||||
Reference in New Issue
Block a user