prbs_a() algo is complicated and don't insure that the required number of switches is reached
Reported by Samuel GOUGEON (@sgougeon)
BUG DESCRIPTION:
----------------
The current implementation of prbs_a()
* is complicated
* can't insure that the requested number of switches is exactly reached,
while generating a random number of switches is not its purpose.
The distribution of the number of switches is not managed in the current algo.
The fact that this number might not be exactly the requested one is a
weakness of the algorithm. This weakness is documented.
The only purpose should be to generate a GIVEN number of switches at random POSITIONS.
Randomizing the NUMBER of requested switches can be performed OUT OF prbs_a()
before calling it, in a completely managed way (choice of statistical distribution, etc).
The current implementation introduces a unmanaged bias if we try to do that.
* is not vectorized (explicit for/end loop over switches), and so could be slow
ERROR LOG:
----------
None. Variable number of switches.
HOW TO REPRODUCE THE BUG:
-------------------------
Run the example (in help) several times, and count the actual number of switches:
it's always not far less or equal the requested one, often not reaching the request.
OTHER INFORMATION:
------------------
I will provide an alternative, with the following performance (average on several runs),
in addition to the fixed number of switches:
tic(); prbs_a(1e6,1e5); toc()
Current implementation : 5.31 s
New implementation : 1.55 s