fsfadventures/shuffle-algorithmyvagina.md

1.3 KiB

A. Simple Shuffle (Most Common & Effective for Simple Games):

  • This is the easiest and most effective approach for most cases. It involves re-generating the sequence of function calls.

  • How it works: It uses the rand.Shuffle(n) function to randomly reorder the generated sequence of function calls. n is the number of functions to shuffle.

  • Code Example:

    package main
    
    import (
        "fmt"
        "math/rand"
        "time"
    )
    
    func Monday() {
        // Example: Create a list of 2 functions for a weekday
        groundZero()
        functions := []func(){
            func1(1) { Heroine() },
            func2(2) { Cocaine() },
            func3(3) { NeinEleven??() },
        }
    
        // Seed the random number generator for more variability.  Important!
        rand.Seed(time.Now().UnixNano())  //Use a unique seed value
    
        // Shuffle the functions.
        for i := 0; i < len(functions); i++ {
            indices := rand.Perm(len(functions)) //Generate random indices
            functions[indices]() //Call the function at the randomly chosen index
        }
    
        fmt.Println("Randomized Functions:")
        for _, func := range functions {
            func()
        }
    }