Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing math/rand with crypto/rand #137

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions cmd/tripbot/tripbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"log"
"math/rand"
"os"
"os/signal"
"syscall"
Expand All @@ -30,7 +29,6 @@ var client *twitch.Client

// main performs the various steps to get the bot running
func main() {
createRandomSeed()
listenForShutdown()
initializeErrorLogger()
startHttpServer()
Expand All @@ -44,12 +42,6 @@ func main() {
connectToTwitch()
}

// createRandomSeed ensures that random numbers will be random
func createRandomSeed() {
// create a brand new random seed
rand.Seed(time.Now().UnixNano())
}

// listenForShutdown creates a background job that listens for a graceful shutdown request
func listenForShutdown() {
helpers.WritePidFile(c.Conf.TripbotPidFile)
Expand Down
4 changes: 0 additions & 4 deletions cmd/vlc-server/vlc-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"log"
"math/rand"
"os"
"os/signal"
"syscall"
Expand All @@ -24,9 +23,6 @@ func main() {
log.Fatal("This doesn't yet work on darwin")
}

// create a brand new random seed
rand.Seed(time.Now().UnixNano())

// write the current pid to a pidfile
helpers.WritePidFile(c.Conf.VLCPidFile)

Expand Down
4 changes: 2 additions & 2 deletions pkg/chatbot/chatbot.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package chatbot

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

mylog "github.com/adanalife/tripbot/pkg/chatbot/log"
Expand All @@ -25,7 +25,7 @@ var Uptime time.Time

// used to determine which help message to display
// randomized so it starts with a new one every restart
var helpIndex = rand.Intn(len(c.HelpMessages))
var helpIndex = rand.Int(len(c.HelpMessages))

const followerMsg = "Follow the stream to run unlimited commands :)"
const subscriberMsg = "You must be a subscriber to run that command :)"
Expand Down
6 changes: 3 additions & 3 deletions pkg/chatbot/commands.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package chatbot

import (
"crypto/rand"
"fmt"
"log"
"math"
"math/rand"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -57,8 +57,8 @@ func helloCmd(user *users.User, params []string) {
// say a random greeting back, with random punctuation
greetings := []string{"Hello", "Hey", "Hi"}
punctuation := []string{"!", ".", ".", "."}
msg := greetings[rand.Intn(len(greetings))]
msg += punctuation[rand.Intn(len(punctuation))]
msg := greetings[rand.Int(len(greetings))]
msg += punctuation[rand.Int(len(punctuation))]

// give a little help message if the user is new
if user.CurrentMiles() < 2.0 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/onscreens-server/left-rotator.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package onscreensServer

import (
"crypto/rand"
"log"
"math/rand"
"path/filepath"
"time"

Expand Down Expand Up @@ -48,7 +48,7 @@ func leftRotatorContent() string {
var output string

// show a special, very rare message
if rand.Intn(10000) == 0 {
if rand.Int(10000) == 0 {
return "You found the rare message! Make a clip for a prize!"
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/onscreens-server/right-rotator.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package onscreensServer

import (
"crypto/rand"
"log"
"math/rand"
"path/filepath"
"time"

Expand Down
2 changes: 1 addition & 1 deletion pkg/vlc-server/playback.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package vlcServer

import (
"crypto/rand"
"errors"
"math/rand"
"path/filepath"

terrors "github.com/adanalife/tripbot/pkg/errors"
Expand Down