Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bad randomness #388

Open
lukew3 opened this issue Dec 6, 2022 · 1 comment
Open

Fix bad randomness #388

lukew3 opened this issue Dec 6, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@lukew3
Copy link
Owner

lukew3 commented Dec 6, 2022

For some generators, the random value of the second value is limited by the random value of the first generated value. This can cause a bad distribution of generated problems, such as the second addend in addition() being on average, less than the first addend.

I think that the best way to fix this is to get rid of things like maxSum and generate terms independent of each other, but this may restrict use cases like elementary students who can only do single term addition not being able to generate problems with terms greater than 4 since you could generate two 5s and get a sum of 10.

@lukew3 lukew3 added the bug Something isn't working label Dec 19, 2022
@YousafZahid1
Copy link

By using the built-in function of the random values either .randint or .randrange you can achieve the question here is the code which can work

import random

def biased_addition():
first_addend = random.randint(1, 10)
second_addend = random.randint(1, first_addend)
return first_addend, second_addend

def balanced_addition():
first_addend = random.randint(1, 10)
second_addend = random.randint(1, 10)
return first_addend, second_addend

biased_result = [biasedaddition() for in range(1000)]
balanced_result = [balancedaddition() for in range(1000)]

biased_average = sum(addend[1] for addend in biased_result) / len(biased_result)
balanced_average = sum(addend[1] for addend in balanced_result) / len(balanced_result)

print("Biased Average:", biased_average)
print("Balanced Average:", balanced_average)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants