How does wblrnd generate random numbers?
Mostrar comentarios más antiguos
Hello,
I was wondering what happens when I set rng(52) and then I call wblrnd four times to generate 4 different numbers.
rng(52); % Setting the seed for random number generation
a = zeros(1, 5);
b = zeros(1, 5);
for i = 1:5
a(i) = wblrnd(4, 3); % Generate random number for a
b(i) = wblrnd(4, 3); % Generate random number for b
end
Each time the code runs, a and b generate the same number. However, the values for a and b are different. In this case, is there a seperate seed for each time wblrand is called? How does the random number generation work behind the hood?
Respuesta aceptada
Más respuestas (1)
rng(52); % Setting the seed for random number generation once for `a`
a = zeros(1, 5);
for i = 1:5
a(i) = wblrnd(4, 3); % Generate random number for a
end
rng(52); % Resetting the seed for random number generation for `b`
b = zeros(1, 5);
for i = 1:5
b(i) = wblrnd(4, 3); % Generate random number for b
end
disp([a])
disp([b])
This approach ensures that the random numbers in a and b are generated from the identical point in the random sequence, leading to identical values in a and b, provided that the parameters for wblrnd remain constant (in your case, both are 4, 3)
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!