Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
System.Random每次给出相同的值3次_Random_F# - Fatal编程技术网

System.Random每次给出相同的值3次

System.Random每次给出相同的值3次,random,f#,Random,F#,可能重复: 我每次都会从列表中得到一个随机值,但我得到的是相同的3次,直到它改变了 守则: let timer = new DispatcherTimer() timer.Tick.Add <| fun _ -> X.Change() timer.Interval <- new TimeSpan(0,0,3) member X.Change() = (Seq.nth (System.Random().Next(S

可能重复:

我每次都会从列表中得到一个随机值,但我得到的是相同的3次,直到它改变了

守则:

let timer = new DispatcherTimer()
timer.Tick.Add  <| fun _ -> X.Change()
timer.Interval  <- new TimeSpan(0,0,3)    

    member X.Change() = 
        (Seq.nth
            (System.Random().Next(Seq.length actions))
                <| actions)()
let timer=new dispatchermer()
timer.Tick.Add X.Change()

timer.Interval我不能完全确定您的示例,但一般的指导原则是您应该创建一个
System.Random
实例(或者如果您有多线程应用程序,则每个线程一个实例),然后多次使用它

试着这样做:

let timer = new DispatcherTimer() 
let rnd = new System.Random()
timer.Tick.Add  <| fun _ -> X.Change() 
timer.Interval  <- new TimeSpan(0,0,3)     

    member X.Change() =  
        (Seq.nth 
            (rnd.Next(Seq.length actions)) 
                <| actions)() 

啊。。。我已经忘记了,谢谢,但在数组中添加操作更难:)这是一个问题。请先搜索。
member X.Change() =  
  actions.[rnd.Next(actions.Length)]()