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 9240389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:10:53+00:00 2026-06-18T08:10:53+00:00

How do I generate random numbers using a Markov model in C#? I noticed

  • 0

How do I generate random numbers using a Markov model in C#? I noticed here that almost all of the applications of the Markov algorithm is for randomly writing text. Is there a source code somewhere or a tutorial where I can fully understand how this works? My goal actually is to generate random numbers to simulate solar energy harvesting.

  • 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-18T08:10:54+00:00Added an answer on June 18, 2026 at 8:10 am

    First decide how deep your Markov model is going. Do you look at the previous number? The previous two numbers? The previous three numbers? Perhaps deeper?

    Second, look through some actual solar energy data and extract the probabilities for what follows a group of 1, 2 or 3 numbers. Ideally you will be able to get complete coverage, but there may well be gaps. For those either extrapolate, or put in some average/random value.

    All this so far is data.

    Third generate the first 1, 2 or 3 numbers. From your database pick the correct combination and randomly select one of the possible followers. When I do this, I have a low probability random element possible as well so things don’t get stuck in a rut.

    Drop the earliest element of your 1, 2 or 3 numbers. Shift the others down and add the new number at the end. Repeat until you have enough data.

    Here is a short extract from my 1-deep Markov word generator showing part of the data table:

    // The line addEntry('h', "e 50 a 23 i 12 o  7 @ 100") shows the the letter
    // 'h' is followed by 'e' 50% of the time, 'a' 23% of the time, 'i' 12% of 
    // the time, 'o' 7% of the time and otherwise some other letter, '@'.
    //
    // Figures are taken from Gaines and tweaked. (see 'q')
    private void initMarkovTable() {
        mMarkovTable = new HashMap<Character, List<CFPair>>(26);
    
        addEntry('a', "n 21 t 17 s 12 r 10 l  8 d  5 c  4 m  4 @ 100");
        addEntry('b', "e 34 l 17 u 11 o  9 a  7 y  5 b  4 r  4 @ 100");
        addEntry('c', "h 19 o 19 e 17 a 13 i  7 t  6 r  4 l  4 k  4 @ 100");
        addEntry('d', "e 16 i 14 a 14 o 10 y  8 s  6 u  5 @ 100");
        addEntry('e', "r 15 d 10 s  9 n  8 a  7 t  6 m  5 e  4 c  4 o  4 w 4 @ 100");
        addEntry('f', "t 22 o 21 e 10 i  9 a  7 r  5 f  5 u  4 @ 100");
        addEntry('g', "e 14 h 14 o 12 r 10 a  8 t  6 f  5 w  4 i  4 s  4 @ 100");
        addEntry('h', "e 50 a 23 i 12 o  7 @ 100");
        // ...
    }
    

    The data is organised as letter-frequency pairs. I used the ‘@’ character to indicate “pick any letter here”. Your data will be number-frequency pairs instead.

    To pick an output, I read the appropriate line of the data and generate a random percentage. Scan long the data accumulating the frequencies until the accumulated frequency exceeds the random percantage. That is the letter (or number in your case) you pick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to generate a bunch of random numbers using rand() % (range). Here's
Using Javascript, how can I generate random numbers that are skewed towards one end
How to generate random numbers using assembly code in the range 1--4 ?
I'm using srandom() and random() to generate random numbers in c on a Unix
I am using matlab's randn function to generate random random numbers from a standard
How can I generate some unique random numbers between 1 and 100 using JavaScript?
Can you tell me any ways to generate non-uniform random numbers? I am using
I need to generate a lot of random numbers. I've tried using random.random but
I am using a uniform_int_distribution in Boost 1.52 to generate random numbers using the
I want to generate the random numbers using this loop. When i runs the

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.