From 67a17e3073b553c45935b8580fba2974acc2bfd0 Mon Sep 17 00:00:00 2001 From: Matheus Sousa <132166437+Matheuzinh0@users.noreply.github.com> Date: Tue, 29 Oct 2024 10:45:01 -0300 Subject: [PATCH] Add files via upload --- code/PRNG1_m32 | Bin 0 -> 16248 bytes code/PRNG1_m32.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++ code/PRNG1_m64.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 code/PRNG1_m32 create mode 100644 code/PRNG1_m32.c create mode 100644 code/PRNG1_m64.c diff --git a/code/PRNG1_m32 b/code/PRNG1_m32 new file mode 100644 index 0000000000000000000000000000000000000000..c1891badfcb5b812890ed9c741af2734f4e0317c GIT binary patch literal 16248 zcmeHOeQX>@6`woj66e#G)S-?8&9x*|0`b)*9DD6^({-xJIN@;!8o0e`o{svu|c^XK!b|sI|AaT`s|?NPJqLwBM_k04c^kK^cI6s23~Y zyg}R{7K6MSB9B+@WYB0jNC#*^jj!x#s)!R6m%Wv=RpO@ zcKidilacjSeLi%C?R&Ih3>%g?{iV^-G^>vV6sZSOo?8x;na($lxKk8cL zc#AW4b0^ieP(K7I{)`k}u{9R$sjJ-@3s=OViOf*NP<>rRU9CTz^jFK8v0Xkma7?xC z=@wATIC2z5;T};kmxsDi(xd$!``o$=M}uc8gM8-36Q6PCwA z1Z5r{XrtosC8Q}Y#QDgpaY-z2LccZh=yn0;n}@#(xcTh+7O>AOz~2Tumi3;b>k#Q) zJ#BqKjN+s-Dv+F$M8X60*Yh2GY+ zTMtK4k^X4fh@`r9H^q{PNLQ#Q7J(xB#U$}dK;*H^WjW|Xz=?np0Ve`Z1e^#s5pW{#{~v+Bm)!BM z;OKO5Fz5N*Rw06i#|^hR8616~_>8GpIym`qq&A#I(o11Eo_{cyy%Ze1Jk!yoRgG7@6g<|j1m>^i+I?Vptek9P-08!q`F8_ZrYRs?eme+D7H4lXnwhSOP( z3+!AEfUi|Q`oH-oC^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w^4lX{=xJ-@YqfsKZ+INW#D}*6yRmx?<$ZvYXZN<4NoiEeJb|#ri?0o z5|-|VdZM}!>K8zyjZ9ykzgOH`=C2!Zy%!hyr@=Cu)ca$}o={8=8_85!4`qf#Z!$g@ zix`oxzjA&H+-VTiL#b3~SdS!()UfDFh2jxCoQcPW!KFab!P1yx+R?eEwMviIR70Z@ zJt7^6gsbGaTBN|YrL%FjrfYkeb=Y*!{P{hNyW5(8hRq$i79?%3xl`z^?R$4Nw(EOa zTJ~vOdRODlb`3o2TO$Iz_2CxV9R^d0er%K;s~37C95O;eUM20Nu!_MQ6c9DgtE~|r z%-tuUhto-YAe0E>9*VZTU=@xg^h`PuhH?{d(tFZr@|AlxLa9VDhCFP);OoYH8S`$o zn7h$qZmTfTLip3eaU;|NXrvSla1J(wL{fvopGX=Je}5w5A50|&BPnCJfa=LaVFOPz zOjP5}whA0b(tIG49uWTUa004OXrz?pKqQrpCKGc69dxNkEQAh}8;lvkFPrIytiL}A zB4*N&Ug0+)Lm=YF0_&vg0e@tG#?n9-N@Gctp$3)m;5<|nibtU^-d_Ol)1BgYB-F>m)j2^_|R%eS5%^c>;$88DH_-v1|n zE%f)1pM~Vdz>g=!XKelfQZTaJLjKR%{5!~j@mBsnxB2fU2gX6}7;1pMykFYuJ)Nao*<5lo2De&j_gYgO=A+ep3ZpzHR3kn>&TtCl;dEYPZ z@5TEM6Z>&L{s1_J&)A)@SIj*1Q zleOe;{r^A?_WoN<^^-XlE7<>Ti%}VDE2cuU#-38i^L{F@o+|tZurTYl;>W)$_@2pa gmyUG$23@$vRyfzowm2Q0&;Q%_V1ra{bFhixKL%Bs1poj5 literal 0 HcmV?d00001 diff --git a/code/PRNG1_m32.c b/code/PRNG1_m32.c new file mode 100644 index 0000000..3fddde1 --- /dev/null +++ b/code/PRNG1_m32.c @@ -0,0 +1,83 @@ +// Adapted from TestU01 manual + +#include "math.h" +#include +#include + +// PRNG 1 com m=32 e l=8 Sem o LFSR + +// Sementes aleatórias +static uint32_t x = 1142458949U; +static uint32_t y = 848535601U; +static double nb = pow(2, 24); +static uint64_t seed1 = 0xBEEFCAFEu;// Sementeinicial +static uint64_t seed2 = 0x5A5A5A5Au;// Semente inicial +static int r=0; +static int s=32; + +//Estrutura para atualizar os valores das coordenadas +typedef struct{ + uint32_t x; + uint32_t y; +}coord_arnold;//assinatura para estrutura +//Função do mapa de Arnold discreto +coord_arnold arnold(uint32_t x, uint32_t y){ +coord_arnold coord; //assinatura para estrutura +unsigned int x_aux; + x_aux = x; + coord.x = (2 * x + y); //% MOD; //coord.x e coord.y armazenam o valor na estrutura via passagem por referência + coord.y = (x_aux + y); // % MOD; + return coord; //retorna os valores com assinados +} +uint32_t prng_m32_l8(void) +{ + + uint32_t Bx0, Bx1, Bx2, Bx3; + uint32_t By0, By1, By2, By3; + unsigned int x_aux; + unsigned int alpha0, alpha1; //unsigned int armanzena valores de até 32bits + + coord_arnold coord;// Assinatura da estrutura + coord=arnold((uint32_t)seed1,(uint32_t)seed2);//Entrada da semente no mapa de Arnold discreto + //Atualizando os valores da estrutura + seed1=coord.x; + seed2=coord.y; + //Atualizando as variáveis x e y para as operações + x=seed1; + y=seed2; + //Divisão em sub-blocos: l=8 então divide-se me l/2 sub-blocos, ou seja, em 4 sub-blocos de 8bits cada. + // Get x[7:0], y[7:0] + Bx0 = x & 0xff; + By0 = y & 0xff; + + // Get x[15:8], y[15:8] + Bx1 = (x & 0xff00) >> 8; + By1 = (y & 0xff00) >> 8; + + // Get x[23:16], y[23:16] + Bx2 = (x & 0xff0000) >> 16; + By2 = (y & 0xff0000) >> 16; + + + // Get x[31:24], y[31:24] + Bx3 = (x & 0xff000000) >> 24; + By3 = (y & 0xff000000) >> 24; + //// { X[47:31] XOR y[31:15] +(OR) X[63:47] XOR Y[15:0]} +(OR) {X[15:0] XOR y[47:31] +(OR) X[31:15] XOR Y[63:47:0]} + alpha0= ((Bx2 ^ By1)<<8 | (Bx3 ^ By0))<<16; + alpha1= ((Bx0 ^ By2)<<8 | (Bx1 ^ By3)); + + return alpha0 | alpha1;// r=m , 32bits +} + +int main() +{ + int sample; + + for (int i = 0; i < 100; i++) + { + sample = prng_m32_l8(); + printf("i: %d, z: %u\n", i, sample); + } + + return 0; +} diff --git a/code/PRNG1_m64.c b/code/PRNG1_m64.c new file mode 100644 index 0000000..e24b60a --- /dev/null +++ b/code/PRNG1_m64.c @@ -0,0 +1,84 @@ +// Adapted from TestU01 manual + +#include "math.h" +#include +#include +// PRNG 1 com m=64 e l=16 + +// Sementes aleatórias +static uint64_t x = 1142458949U; +static uint64_t y = 848535601U; +//uint64_t x,y; +static double nb = pow(2, 24); +static uint64_t seed1 = 0xBEEFCAFEu;// Sementeinicial +static uint64_t seed2 = 0x5A5A5A5Au;// Semente inicial +static int r=0; +static int s=32; + +//Estrutura para atualizar os valores das coordenadas +typedef struct{ + uint64_t x; + uint64_t y; +}coord_arnold;//assinatura para estrutura +//Função do mapa de Arnold discreto +coord_arnold arnold(uint64_t x, uint64_t y){ +coord_arnold coord; //assinatura para estrutura + uint64_t x_aux; + x_aux = x; + coord.x = (2 * x + y); //% MOD; //coord.x e coord.y armazenam o valor na estrutura via passagem por referência + coord.y = (x_aux + y); // % MOD; + return coord; //retorna os valores com assinados +} +uint64_t prng_m64_l16(void) +{ + + uint64_t Bx0, Bx1, Bx2, Bx3; + uint64_t By0, By1, By2, By3; + uint64_t alpha0, alpha1; + + coord_arnold coord;// Assinatura da estrutura + coord=arnold((uint64_t)seed1,(uint64_t)seed2);//Entrada da semente no mapa de Arnold discreto + //Atualizando os valores da estrutura + seed1=coord.x; + seed2=coord.y; + //Atualizando as variáveis x e y para as operações + x=seed1; + y=seed2; + //Divisão em m/l sub-blocos, 4 sub-blocos com comprimento de 16bits + //Sub-blocos de maior índice possuem os bits mais significativos + // Get x[15:0], y[15:0] + Bx0 = x & 0xffff; + By0 = y & 0xffff; + + // Get x[31:15], y[31:15] + Bx1 = (x & 0xffff0000) >> 16; + By1 = (y & 0xffff0000) >> 16; + + // Get x[47:31], y[47:31] + Bx2 = (x & 0xffff00000000) >> 32; + By2 = (y & 0xffff00000000) >> 32; + + // Get x[63:47], y[63:47] + Bx3 = (x & 0xffff000000000000) >> 48; + By3 = (y & 0xffff000000000000) >> 48; +// { X[47:31] XOR y[31:15] +(OR) X[63:47] XOR Y[15:0]} +(OR) {X[15:0] XOR y[47:31] +(OR) X[31:15] XOR Y[63:47:0]} + alpha0= ((Bx2 ^ By1)<<16 | (Bx3 ^ By0))<<32;//32bits mais significativo + alpha1= ((Bx0 ^ By2)<<16 | (Bx1 ^ By3));//32bits menos significativos + + return alpha0|alpha1; //64bits r=m + +} + + +int main() +{ + uint64_t sample; + + for (int i = 0; i < 100; i++) + { + sample = prng_m64_l16(); + printf("i: %d, z: %lu\n", i, sample); + } + + return 0; +}