Skip to content

Uncategorized

How to test randomness?

In this blog I want to show you one way of how to test randomness. Randomness often appears when programming games. Let’s say you have a class that uses randomness, like a dice. When someone throws a dice it can be in one of six states 1,2,3,4,5 or 6. Thus you might implement the dice using a Java Random like the next example code shows. Can you test that class? A natural reflex is to say: “No, you can’t test it, because a test always makes an assumption about the result. Since the result is random you can never make an assumption that will always come true. Thus the test… Read More »How to test randomness?

GDPR Cookie Consent with Real Cookie Banner