함수 rand choice()

1 개요[ | ]

함수 rand_choice()

2 Go[ | ]

package main

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

func main() {
	fruits := []string{"apple", "banana", "melon"}

	rand.Seed(time.Now().Unix())
	f := fruits[rand.Intn(len(fruits))]
	fmt.Println(f)
}

3 JavaScript[ | ]

const fruits = ['apple', 'banana', 'melon'];
const f = fruits[Math.floor(Math.random() * fruits.length)];
console.log(f);

4 Lua[ | ]

local fruits = { 'apple', 'banana', 'lemon', 'melon' }
print( fruits[ math.random( #fruits ) ] )

5 PHP[ | ]

<?php
$fruits = ['apple', 'banana', 'melon'];
$f = $fruits[array_rand($fruits, 1)];
var_dump($f);

6 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}