Member-only story

How To Use Rand.Seed and Rand.Shuffle() in Go

Add Some Randomness To Your Structs

Aravind
5 min readJun 27, 2023
Photo by Simone Secci on Unsplash

We all know life can be random.

Why not embrace randomness then?

Let’s see how we can use Go to simulate random behaviour.

Use Cases of Randomness

  1. Randomizing the order of items: If you’re creating a quiz application, for instance, you might want to randomize the order of questions or the order of answer choices for each question to prevent cheating or rote learning (Rote learning is a memorization technique based on repetition. The idea is that one will be able to quickly recall the meaning of the material the more one repeats it).
  2. Machine Learning: In machine learning, it’s common to shuffle your data before splitting it into training and test sets to ensure that your training set is representative of the whole data set.
  3. Games: Many games, such as card games or board games, need to shuffle decks or lists of items to ensure fair play and unpredictability.
  4. Load Balancing: In a distributed system, shuffling can help distribute the load evenly. For example, you can shuffle a list of servers and then assign each incoming request to a server in order.
  5. A/B Testing: If you’re conducting an A/B…

--

--

Aravind
Aravind

Written by Aravind

I help you continuously improve your life, ranging from health, serverless/devops & mindset. Personal views.

No responses yet