---
title: Guess the random number
description: Guess the random number is a programming kata where the player has three attempts to guess what number has been randomly generated.
---

[Katas ](https://www.codurance.com/katas)

# [Guess the random number](https://www.codurance.com/katas/random-number-kata)

 Written by [Emmanuel Valverde](https://www.codurance.com/katas/author/emmanuel-valverde) | Sep 24, 2022 7:00:00 AM

## What do we want to build?

We want to create a small game. The game consists of a player trying to guess a random number. The player will have three attempts to guess the number. If the number is correctly guessed, then the player wins, if not, the player loses.

If the player fails to guess the number, the game must notify the user if the number it's higher or lower.

## What do we try to work out with this kata?

This kata is meant to work on test doubles. But it can also be solved without them. Also, it's an excellent kata to work on Primitive obsession and baby steps.

## Business rules

- The user starts playing, the game generates a random number that must not change until the game it's over.
- If the user guesses the number the player wins.
- If the user does not guess the number the system would have to notify the user if the number it's higher or lower.
- If the user does not guess the number on three intents it will lose.

## Use cases

### The player wins on the first move

> ```
> As playerI play the number 5the player wins
> ```

 

 

| Initial state | Player wins on the first move |
| --- | --- |
|  |  |

 

### The player wins not on the first intent

> ```
> As playerI play a 10I play a 3I play a 5the player wins
> ```

 

| Initial state | Player first move | Player second move | Player third move |
| --- | --- | --- | --- |
|  |  |  |  |

 

### The player loses the game

> ```
> As playerI play a 10I play a 3I play a 5the player loses
> ```

 

| Initial state | Player first move | Player second move | Player third move |
| --- | --- | --- | --- |
|  |  |  |  |

 

## Possible API of the class

```
public class GuessingNumberGame {
```

## What can I practice with this kata

- Working with collaborators
- Baby steps
- Object Calisthenics
- Test doubles

[View full post](https://www.codurance.com/katas/random-number-kata)

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Emmanuel Valverde"
  },
  "dateModified" : "2023-04-20T12:49:23.970Z",
  "datePublished" : "2022-09-24T07:00:00Z",
  "headline" : "Guess the random number",
  "image" : {
    "@type" : "ImageObject",
    "height" : 630,
    "url" : "https://3042464.fs1.hubspotusercontent-na1.net/hubfs/3042464/Katalyst/Thumbnails/Katalyst_Thumbnail_Guess%20the%20random%20Number%20%E2%80%93%202.jpg",
    "width" : 1200
  },
  "mainEntityOfPage" : "https://www.codurance.com/katas/random-number-kata",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : 60,
      "url" : "/hs/hsstatic/content_shared_assets/static-1.4092/img/default-amp-logo.png",
      "width" : 60
    },
    "name" : "Katas"
  }
}
```