1
b=round(rand(1,20));

Instead of using the function rand, I would like to know how to create such series.

Xcoder
  • 1,433
  • 3
  • 17
  • 37
Ketaki_S
  • 21
  • 3

1 Answers1

0

This is a very interesting question. Actually, the easiest way to go, in my opinion is to use a Linear-feedback Shift Register. You can find plenty of examples and implementations googling around (here is one coming from another SO question).

Here is a quick Matlab demo based on this code:

b = lfsr(20)

function r = lfsr(size)
    persistent state;

    if (isempty(state))
        state = uint32(1);
    end

    if (nargin < 1)
        size = 1;
    end

    r = zeros(size,1);

    for i = 1:size
        r(i) = bitand(state,uint32(1));

        if (bitand(state,uint32(1)))
            state = bitxor(bitshift(state,-1),uint32(142));
        else
            state = bitshift(state,-1);
        end
    end
end
Tommaso Belluzzo
  • 23,232
  • 8
  • 74
  • 98