Generate random binary sequence with a specific ratio
问题 I want to generate a random binary sequence with a ratio of 50%, that is, the same amounts of 0s and 1s. This is what I have so far: length_sequence = 1000; ratio = 0.5; A = logical(randi([0 1],length_sequence,1)); The only problem is that I dont know how to set the ratio. 回答1: The ratio can be interpreted as deterministic (you want 500 ones and 500 zeros in each realization of 1000 values) or as probabilistic (a realization may have more ones than zeros, but the ratio holds over a very large