第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Golang程序中的隨機(jī)函數(shù)和持久化

Golang程序中的隨機(jī)函數(shù)和持久化

Go
開滿天機(jī) 2021-12-07 19:41:51
我想要做的是看看是否有一種方法可以創(chuàng)建一個(gè)隨機(jī)函數(shù)或使用一個(gè)內(nèi)置函數(shù),該函數(shù)能夠使用知道該程序中的哪些食物是從隨機(jī)選擇中選擇的,并且不再用于另一個(gè)星期?我目前有 1-6 種食物,但我想確保一周內(nèi)不會(huì)連續(xù)兩次選擇相同的食物,例如 2。此外,我希望程序能夠?qū)懴伦詈筮x擇的項(xiàng)目,這樣它至少一周內(nèi)不會(huì)再次選擇它。我能用一個(gè)可以讀取的簡(jiǎn)單文本文件來(lái)完成這個(gè)嗎?package mainimport (    "fmt"    "math/rand"    "time")type Recipe struct { //Struct for recipe information    name        string    prepTime    int    cookTime    int    Ingredients []string //this is now a slice that will accept multiple elements    ID          int    Yield       int}func main() {    var recipe1 Recipe //Declare recipe1 of Type Recipe    var recipe2 Recipe    var recipe3 Recipe    /* recipe1 specifications */    recipe1.name = "BBQ Pulled Chicken"    recipe1.prepTime = 25    recipe1.cookTime = 5    recipe1.Ingredients = append(        recipe1.Ingredients,        "1 8-ounce can reduced-sodium tomato sauce",    )    recipe1.Ingredients = append(        recipe1.Ingredients,        "1/2 medium onion (grated),",    )    recipe1.ID = 1    recipe1.Yield = 8    /* Recipe 2 specifications */    recipe2.name = "Steak Tacos with Pineapple"    recipe2.prepTime = 45    recipe2.cookTime = 45    recipe2.Ingredients = append(        recipe2.Ingredients,        "3 tablespoons soy sauce,",    )    recipe2.Ingredients = append(        recipe2.Ingredients,        "1 tablespoon finely grated garlic,",    )    recipe2.Ingredients = append(        recipe2.Ingredients,        "1 tablespoon finely grated peeled fresh ginger,",    )    recipe2.Ingredients = append(        recipe2.Ingredients,        "1 1/2 pounds skirt steak, cut into 5-inch lengths,",    )    recipe2.Ingredients = append(        recipe2.Ingredients,        "Salt",    )    recipe2.Ingredients = append(        recipe2.Ingredients,        "Pepper",    )
查看完整描述

1 回答

?
弒天下

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超8個(gè)贊

Perm 可能是您想要使用的。這是一個(gè)將為您生成偽隨機(jī)列表的示例。您可以將其保存到 json 編碼的文件中。然后,如果您有 7 個(gè)食譜,您可以使用 time.Weekday 從切片中獲取食譜編號(hào),使用星期幾作為切片的關(guān)鍵。一旦您達(dá)到某個(gè)預(yù)定日期,只需重新生成切片并保存。


package main


import "fmt"

import "math/rand"

import "time"


func main() {


  r := rand.New(rand.NewSource(time.Now().UnixNano()))

  i := r.Perm(6)

  fmt.Printf("%v\n", i)

}


查看完整回答
反對(duì) 回復(fù) 2021-12-07
  • 1 回答
  • 0 關(guān)注
  • 209 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)