Generating two Random sequences

What is the best way to generate two random sequences that are 100 characters long and randomly comprised of +1 and -1. Also what is the best way to capture those values and plot in a histogram for each sequence, as well as the spectral analysis for each sequence?

3 Comments

When you say "randomly comprised" what do you mean?
  • Exactly 50 of the 100 elements of the result are +1 and exactly 50 are -1, but the order in which they appear in the result is random?
  • Any individual element is 50% likely to be +1 and 50% likely to be -1?
  • Any element has probability p of being +1 and (1-p) of being -1? When p is 0.5 this simplifies to the second case.
  • You have a transition matrix giving the probability of the next element being +1 or -1 if the current element is +1 or -1? In the example below, most of the time +1 follows +1 and -1 follows -1 but the result can switch. [This requires Statistics and Machine Learning Toolbox.]
tr = [0.95,0.05; 0.10,0.90];
e = [1 0; 0 1];
[seq, states] = hmmgenerate(100, tr, e, 'Symbols', ["+1", "-1"]);
table(seq.', states.')
It is essentially a coin flip. So to answer your first bullet point question, yes.
The coin flip is bullet point 2, not 1, because 100 coin tosses will rarely end up exactly 50/50.

Sign in to comment.

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 19 Jan 2021
Edited: KALYAN ACHARJYA on 19 Jan 2021
Hint: One Way, you can do multiple ways
data=repmat([1,-1],[1,50])
seq1=data(randperm(100));
seq2=data(randperm(100));
Fore histogram, refer hist function

Products

Asked:

on 19 Jan 2021

Commented:

on 19 Jan 2021

Community Treasure Hunt

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

Start Hunting!