Surprising behavior in randsample
이전 댓글 표시
1. Generating sequences with replacement -- not surprising
When I generate sequences with replacement (after setting the same seed), the first N values generated are the same, regardless of how many values I generate:
seed = 13;
N = 12;
for ni = 1:N
rng(seed)
fprintf("randsample (with replace), %2d value(s): ",ni); fprintf('%g ', randsample(N,ni,true)'); fprintf("\n");
end
2. Generating sequences without replacement -- surprising
When I generate sequences without replacement (after setting the same seed), I expected the same behavior. And that is the behavior -- but only if the sequence is long enough. For shorter sequences, the values are not in the same order.
seed = 13;
N = 12;
for ni = 1:N
rng(seed)
fprintf("randsample (without replace), %2d value(s): ",ni); fprintf('%g ', randsample(N,ni,false)'); fprintf("\n");
end
Notice how the first three rows don't follow the pattern. This seems odd to me, and perhaps buggy. (The behavior is consistent, and doesn't depend on the particular seed.)
I'm not sure I have a question, other than ... "Does this seem strange to anyone else?"
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Triangular Distribution에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!