# reproduce random numbers for the third dimension

1 view (last 30 days)
Pooneh Shah Malekpoor on 21 Apr 2021
Answered: James Tursa on 21 Apr 2021
Hello
I want to generate random numbers for matrix A which has a second page(i.e. 2), whose values i am going to assign to another varaiable in my code. Though i have the rng command to reproduce the same random numbers, the very numbers in the second page do vary in every iteration..How can I regenerate the same random numbers in each iteration for the second page of my matrix A? Any idea is highly appreciated.
rng('default');
rng(1);
Nmc=200
uu=1
A=rand(Nmc,uu+1,2);
Pooneh Shah Malekpoor on 21 Apr 2021
Thanks for your reply. However, let me explain a bit more clearly. in the first itertaion (i.e. Nmc=1) , i need
(:,:,1) =
.109 .2
.323 .50
.15 .6
and
(:,:,2) =
.17 .16
.84 .91
.153 .65
Again in the second iteration(i.e. Nmc=2), i want:
(:,:,1) =
.109 .2
.323 .50
.15 .6
and
(:,:,2) =
.17 .16
.84 .91
.153 .65

James Tursa on 21 Apr 2021
If you don't want the random numbers to change from iteration to iteration, then don't regenerate them inside the loop. Calculate them once, before the loop starts, and then reuse them over and over within the loop.