golang can generate random numbers. A random number is unknown before running: it’s like telling the computer, give me any number.

Random numbers in computing are not truely random, they are often based on a pseudo random number generator algorithm. Eitherway for most program that degree of randomness is enough.

In this article you will learn how to generate random numbers.

## Random number in golang

### Example

The golang program below generates a number between 0 and 10. The starting number (0) is not given and thus 0 is assumed as lowest number.

1 | package main |

To generate a number between 20 and 40 you can use the code below:

1 | rand.Intn(max-min) + min |

### Exercises

- Make a program that rolls a dice (1 to 6)
- Can you generate negative numbers?