Generate a 32-bit binary stream
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Steve Rogerson
el 21 de Feb. de 2020
Comentada: Steve Rogerson
el 26 de Feb. de 2020
I am trying to genrate a binary stream using this function and have searched a lot but came out emty.
The main problem I am facing is mainly the binary addition on every addition and the size of the increasing stream.
The Equation is below:

I tried to use the rand fucntion but it isnt right. I realised the Binary addition was not happening.
The final result should be a float number within [0,1).
pold = [];
pf=0;
for i=1:32
param = round(rand(1,1));
pf = param + pf;
pold(i) = pf*2^(-i);
pold(i);
end
0 comentarios
Respuesta aceptada
Walter Roberson
el 22 de Feb. de 2020
sum(randi([0,1],1,32).*2.^-(0:31))
Or
randi([0,2^32-1])/2^32
Or you can use rnd() or related to tell rand to use the shr3cong generator, which has the required results.
Or you could rand() and throw away bits 33 to 52.
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!