Skip to content

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

Open
neeco1991 wants to merge 1 commit intoQiskit:mainfrom
neeco1991:4438
Open

CHSH game example error: random.randint(0, 2) generates invalid inputs #4439
neeco1991 wants to merge 1 commit intoQiskit:mainfrom
neeco1991:4438

Conversation

@neeco1991
Copy link

Closes #4438

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@qiskit-bot
Copy link
Contributor

Thanks for contributing to Qiskit documentation!

Before your PR can be merged, it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. Thanks! 🙌

One or more of the following people are relevant to this code:

@neeco1991 neeco1991 changed the title 4438 CHSH game example error: random.randint(0, 2) generates invalid inputs Dec 18, 2025
@jlapeyre
Copy link
Contributor

jlapeyre commented Feb 9, 2026

@christopherporter1 Can we close this?

This PR #4474 was merged and closes #4438, the same issue linked to the present PR, #4439.

Both PRs #4474 and #4439 appear to make the same change. #4439 was opened on Dec. 18. PR #4474 was opened later, on Jan 5. Was this PR overlooked?

In any case both these (identical) PRs are incorrect. There is a confusion between base python's random and numpy.random.

@miamico @abbycross

github-merge-queue bot pushed a commit that referenced this pull request Feb 9, 2026
The existing code that generates


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

imports both `pi` and `random` from numpy. The notebook uses nothing
else from numpy. These two objects are used only in a scalar context. In
some cases, using numpy can degrade performance. In qiskit there has
been an effort, reflected in PRs, to avoid using numpy habitually, when
not necessary. This is done even in non-performance critical code.

This PR changes the code to import `pi` from `math`. And it imports
`random` from the stdlib. When producing single samples, standard
library `random.randint` is about 5 times faster than
`numpy.random.randint`.

Furthermore, the existing code calls numpy's `random.randint(0, 1)`,
which always returns zero. This was mistakenly introduced. Since this PR
uses `randint` from the standard library, the range is 0 to 1,
inclusive. So it may return either 0 or 1. My best understanding is that
this is the original intent of the code.

The following issues and PRs are on exactly the same code touched here
* #4438
* #4439
* #4474 
* #4643 

Closes #4643

---------

Co-authored-by: abbycross <across@us.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

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

3 participants