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.
Learn How To Code: Google’s Go (golang) Programming Language
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.
To generate a number between 20 and 40 you can use the code below:
rand.Intn(max-min) + min
- Make a program that rolls a dice (1 to 6)
- Can you generate negative numbers?