[Golang] A program that determines the turn with random numbers

Introduction

There was a request from the list of lists to make ** x people **, so I wrote it in go language.

package main

import (
	"fmt"
	"math/rand"
	"time"

)

func main() {
	list := [...]string{"mano", "hiori", "meguru",
		"kogane", "mmm", "mitsumine", "sakuya", "kiriko",
		"kaho", "choko", "jyuri", "rinze", "natsuha",
		"amana", "tenka", "chiyuki",
		"asahi", "huyu", "mei",
		"toru", "higuchi", "pya", "hinana"}

	//How to divide
	parse := 5
	//A slice that holds the random numbers that appear
	var slice []int
	rand.Seed(time.Now().UnixNano())

	for i := 1; i < len(list)+1; i++ {

		var r int
		//Random number generation
		for {
			r = rand.Intn(len(list))
			if !contains(slice, r) {
				slice = append(slice, r)
				break
			}
		}

		fmt.Printf("%v ", list[r])

		if i%parse == 0 {
			fmt.Println("")
		}
	}

}

func contains(s []int, e int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}

Output result example

huyu amana kaho asahi toru
kogane kiriko mano rinze meguru
hiori mitsumine sakuya higuchi jyuri
natsuha tenka chiyuki pya choko
mei mmm hinana

https://gawawa124.hatenablog.com/entry/2015/04/08/193237

https://takeshiyako.blogspot.com/2015/10/go-lang-rand.html

Recommended Posts

[Golang] A program that determines the turn with random numbers
I made a program that automatically calculates the zodiac with tkinter
Create a compatibility judgment program with the random module of python.
[Python] A program that creates stairs with #
[Python] A program that rounds the score
A model that identifies the guitar with fast.ai
A program that searches for the same image
A shell program that displays the Fibonacci sequence
[Python] A program that calculates the difference between the total numbers on the diagonal line.
[Python] A program that counts the number of valleys
[Python] Generate random numbers that follow the Rayleigh distribution
A story that struggled with the common set HTTP_PROXY = ~
A memo that I touched the Datastore with python
[Python] A program that compares the positions of kangaroos.
Measure the importance of features with a random forest tool
A program that removes specific characters from the entered text
A program that just presses and releases the Esc key
Is there a bias in the numbers that appear in the Fibonacci numbers?
[Python] A program that finds the most common bird types
[Python] A program that finds the maximum number of toys that can be purchased with your money
Create a program that can generate your favorite images with Selenium
I made a program that solves the spot the difference in seconds
Count the maximum concatenated part of a random graph with NetworkX
[Ev3dev] Create a program that captures the LCD (screen) using python
Try to write a program that abuses the program and sends 100 emails
A program that determines whether a number entered in Python is a prime number
A program that answers a few questions and predicts the next answer
The story of making a module that skips mail with python
[Python] A program that rotates the contents of the list to the left
Testing with random numbers in Python
A function that returns a random name
The story of writing a program
A story that visualizes the present of Qiita with Qiita API + Elasticsearch + Kibana
[Python] A program that calculates the number of chocolate segments that meet the conditions
The LXC Web Panel that can operate LXC with a browser was wonderful
I tried to create a program to convert hexadecimal numbers to decimal numbers with python
[Python] A program that calculates the number of socks to be paired
Extract lines that match the conditions from a text file with python
A program that will slowly recover the economy from any news headline
A function that generates a list with up to 3 prime numbers as elements
Convert the program that imports Google's client library to .exe with pyinstaller
[Python] Generate random numbers that follow the Rayleigh distribution
Search the maze with the python A * algorithm
A typed world that begins with Python
A code that corrects the yoon / sokuon (sokuon)
A program that plays rock-paper-scissors using Python
Arrange the numbers in a spiral shape
An article that just tries a little HTTP request with the curl command
Turn off the dialog that appears when you enter Linux with Remote Desktop
Around the authentication of PyDrive2, a package that operates Google Drive with Python
The story of making a web application that records extensive reading with Django
[Python] A program that finds the minimum and maximum values without using methods
[Python] A program that calculates the number of updates of the highest and lowest records
Turn multiple lists with a for statement at the same time in Python
I made a Python program for Raspberry Pi that operates Omron's environmental sensor in the mode with data storage