Hi, I want to generate 12 different sets of random variables whose elements be fixed in every run. Because these data are inputs of other codes and must be fixed. How can I do this.

matlab programing

2 Comments

Do you mean that the elements in one set must be a permutation of the elements in another set?
I agree with Walter. Do you want a permutation of 12 numbers, or do you just want to regenerate the same random variables each time. The rng command should do the latter.

Sign in to comment.

Answers (1)

Use rng() to get the same sets of numbers each time:
% Initialize random number generator with a constant seed to start.
rng(1); % Pick any seed number you want
% The following 12 sets will always be the same in every run.
set1 = rand(1,5)
set2 = rand(1,5)
set3 = rand(1,5)
set4 = rand(1,5)
set5 = rand(1,5)
set6 = rand(1,5)
set7 = rand(1,5)
set8 = rand(1,5)
set9 = rand(1,5)
set10 = rand(1,5)
set11 = rand(1,5)
set12 = rand(1,5)

Categories

Find more on Random Number Generation in Help Center and File Exchange

Asked:

on 12 Jan 2016

Answered:

on 12 Jan 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!