-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom.go
More file actions
38 lines (32 loc) · 802 Bytes
/
random.go
File metadata and controls
38 lines (32 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package random
import (
"fmt"
"github.com/go-chat-bot/bot"
"math/rand"
)
func genRandom(cmd *bot.Cmd) (msg string, err error) {
if len( cmd.Args) == 0 {
msg = fmt.Sprintf( "%d", rand.Int())
} else if len( cmd.Args) == 1 {
switch cmd.Args[0] {
case "int":
msg = fmt.Sprintf( "%d", rand.Int())
case "uint":
msg = fmt.Sprintf( "%d", rand.Uint32())
case "float":
msg = fmt.Sprintf( "%f", rand.Float32())
default:
msg = "Unknown type: "+cmd.Args[0]
}
} else {
msg = "Invalid number of arguments"
}
return
}
func init() {
bot.RegisterCommand(
"rnd",
"Generate a random number: rnd [type] [min max]",
"",
genRandom)
}