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)]()