How binary Random number generation upto n nodes ?

1 Ansicht (letzte 30 Tage)
ankanna
ankanna am 15 Mär. 2021
Kommentiert: Jan am 24 Apr. 2021
i was do this
clc;
clear all;
close all;
% Link is (n-1)*node/2
node = 3;
offset = 1;
L = (node-offset)*node/2;
c =2^L;
% Generate c binary values:
r = randi([0, 1], c,L);
disp(r);
output:
0 0 1
1 0 0
1 0 0
1 0 1
1 1 0
1 0 0
0 1 0
0 0 1
but i want
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
please help me how to generate binary random numbers up to n in order wise
  1 Kommentar
James Tursa
James Tursa am 15 Mär. 2021
Your current code generates random patterns. But what you want is not random at all ... it is an ordered list. Why do you write you want random output but then show a non-random ordered list as what you want?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

James Tursa
James Tursa am 15 Mär. 2021
Here is how to get your stated desired output, but this is not random at all:
r = dec2bin(0:(2^L-1)) - '0';
  4 Kommentare
ankanna
ankanna am 24 Apr. 2021
n = 3;
Link=(n*(n-1))/2;
c=2^Link;
NN = toeplitz(Link+1:-1:2)
mask = logical(fliplr(diag(ones(1,Link-1),-1)));
NN(mask) = 1;
for c = 0:2^Link-1
l = bitget(c, NN)
end
the above code i generate all configuration matrix.
i need to generate all paths in this network.
please help me to generate all paths in the network
Jan
Jan am 24 Apr. 2021
This is a new question. Please ask it in a new thread.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Random Number Generation finden Sie in Help Center und File Exchange

Produkte


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by