Skip to content

CHSH game example error: random.randint(0, 2) generates invalid inputs #4438

@neeco1991

Description

@neeco1991

URL to the relevant course

https://quantum.cloud.ibm.com/learning/en/courses/basics-of-quantum-information/entanglement-in-action/qiskit-implementation#qiskit-implementation-1

Select all that apply

  • new content request
  • typo
  • code bug
  • out-of-date content
  • broken link
  • other

Describe the fix or the content request.

I encountered an issue in the CHSH game code example where the input bits $x$ and $y$ are generated using an incorrect range. The code currently uses:

x, y = random.randint(0, 2), random.randint(0, 2)

But random.randint(0, 2) ranges from 0 to 2, which doesn't make sense for a bit.
in fact, if you run the whole code, you get:

Fraction of games won: 0.617

Which is wrong for my understanding. I believe the correct code sould be:

x, y = random.randint(0, 1), random.randint(0, 1)

With this fix, the code correctly outputs a win fraction of ~0.85.

For new content requests - if the request is accepted, do you want to write the content?

I will write (or already have written) a draft of the proposed content

Metadata

Metadata

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions