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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:02:37+00:00 2026-06-14T12:02:37+00:00

I got a litte problem understanding conceptually the structure of a random writing program

  • 0

I got a litte problem understanding conceptually the structure of a random writing program (that takes input in form of a text file) and uses the Markov algorithm to create a somewhat sensible output.

So the data structure i am using is to use cases ranging from 0-10. Where at case 0: I count the number a letter/symbol or digit appears and base my new text on this to simulate the input. I have already implemented this by using an Map type that holds each unique letter in the input text and a array of how many there are in the text. So I can simply ask for the size of the array for the specific letter and create output text easy like this.

But now I Need to create case1/2/3 and so on… case 1 also holds what letter is most likely to appear after any letter aswell. Do i need to create 10 seperate arrays for these cases, or are there an easier way?

  • 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-14T12:02:40+00:00Added an answer on June 14, 2026 at 12:02 pm

    There are a lot of ways to model this. One approach is as you describe, with an multi-dimensional array where each index is the following character in the chain and the final result is the count.

    # Two character sample:
    int counts[][] = new int[26][26]
    # ... initialize all entries to zero
    
    # 'a' => 0, 'b' => 1, ... 'z' => 25
    # For example for the string 'apple'
    # Note: I'm only writing this like this to show what the result is, it should be in a
    #       loop or function ...
    counts['a'-'a']['p'-'a']++
    counts['p'-'a']['p'-'a']++
    counts['p'-'a']['l'-'a']++
    counts['l'-'a']['l'-'e']++
    

    Then to randomly generate names you would count the number of total outcomes for a given character (ex: 2 outcomes for ‘p’ in the previous example) and pick a weighted random number for one of the possible outcomes.

    For smaller sizes (say up to 4 characters) that should work fine. For anything larger you may start to run into memory issues since (assuming you’re using A-Z) 26^N entries for an N-length chain.

    I wrote something like a couple of years ago. I think I used random pages from Wikipedia to for seed data to generate the weights.

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

Sidebar

Related Questions

I got a little problem, I got a code, that reads all pixels and
I got a little problem i need a sql query that gives all rows
I've got a little Problem with SDL: When starting my Program (on Archlinux 64bit),
I have a problem that comes from me following tutorials without really understanding what
I've got a little problem. I am applying some changes to an iOS program
I got a little problem to understand where should I add an method that
got a little problem with receiving the contents of a xml file (using TouchXML).
I've got a little problem that's slightly frustrating. Is it possible to set a
I've got a little problem understanding following gmake syntax: OBJ = foo.o bar.o $(OBJ):
I got little problem. I'm refreshing my sdcard using: sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse(file:// + Environment.getExternalStorageDirectory())));

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.