Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8575923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:48:21+00:00 2026-06-11T19:48:21+00:00

Possible Duplicate: F# getting a list of random numbers I’m getting random value from

  • 0

Possible Duplicate:
F# getting a list of random numbers

I’m getting random value from list each time on tick (timer) but I’m getting the same 3 times only then it changes…

the code:

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

Why? I want to get different value each time

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:48:22+00:00Added an answer on June 11, 2026 at 7:48 pm

    I’m not entirely sure about your example, but the general guideline is that you should create one instance of System.Random (or one instance per thread, if you have a multi-threaded application) and then use it multiple times.

    Try something like this:

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

    The Random object is mutable and keeps some state that is used to generate the sequence of random values. When you create a new instance, it initializes the state using current time, so if you create multiple instances at the same time, you’ll get the same numbers.

    As an aside, if you need to access random elements of actions, then it would be better to store them as an array, because then you can just write:

    member X.Change() =  
      actions.[rnd.Next(actions.Length)]()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Getting Filename from file descriptor in C Obtain filename from file pointer
Possible Duplicate: Getting a FILE* from a std::fstream Is there a way to obtain
Possible Duplicate: Getting the timestamp from last saturday (every week)? If today is Sunday,
Possible Duplicate: Getting JavaScript object key list How to iterate json data in jquery
Possible Duplicate: Threads in PHP. I m getting a list of 20 urls. I
Possible Duplicate: Getting Filename from file descriptor in C Is there a simple and
Possible Duplicate: Getting Enum value via reflection With mytype.ReflectedType.GetFields() I can get the constants
Possible Duplicate: How do I get a distinct, ordered list of names from a
Possible Duplicate: Getting value of a PasswordBox that's inside a ListView I have a
Possible Duplicate: Getting python.exe path at run time I have a python app that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.