Binornd draws '1' every time
3 views (last 30 days)
I'm running a script in which I use binornd(1,0.5) within a for loop, and the output is '1' every time. When I copy paste to the command window, it behaves as expected (I haven't done a full statistical test, but at least I get both '0's and '1's as outputs). In the same script, I use randi, which seems to be behaving normally..
Moving the binornd line to different positions in the script does not make a difference, and neither does adding rng('shuffle') just above. Finally, I use binornd(1,p) in another loop, where p varies on each iteration, and I also get only '1's as outputs. So it seems to be a problem specific to binornd.
Jos (10584) on 8 Jul 2014
what if you execute
just before the calls? Do the outputs differ based on the situation (script vs. command line). It could be that you have two different versions ...
Shashank Prasanna on 8 Jul 2014
Edited: Shashank Prasanna on 8 Jul 2014
Why don't you generate all of your random numbers before hand and just use index into the array at each loop iteration? It should be faster and cleaner:
randBin = binornd(limit,0.5);