Skip to content
Advertisement

What statistical tests can I run to test the randomness of binary strings using python?

I’m having issues implementing the block frequency test in Python to understand the randomness of a binary string. I was wondering if anyone would be able to help me out in understanding why the code wont run.

Also, are there any statistical tests to test the randomness of a binary string in Python or possibly Matlab?

JavaScript

Advertisement

Answer

There are three issues that I see with your code.

  1. Using a hardcoded value in two different places. This is bad practice and error prone. I know this probably isn’t what the OP was referring to, but it’s worth fixing while we’re at it.
  2. A string of binary bits (especially one comparing to “1” further down) should be encapsulated in quotation marks, not parentheses. That’s one of the errors being thrown, ’cause the way it’s written now you’ve got a large integer which your trying to “index”. (This goes along with using len where necessary and some other minor changes).
  3. You’re using the wrong module…You probably mean to use scipy.special.gammainc and not tokenize.Special.gammaincc, which doesn’t exist anyhow.

Putting it all together, try something like:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement