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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:52:41+00:00 2026-05-22T18:52:41+00:00

I want to randomly generate points. Well at least there should be a limitation

  • 0

I want to randomly generate points. Well at least there should be a limitation on the y-axis. Later I connect the points to a line which should proceed in a simple animation. You can imagine this as a random walk of a drunken person, going uphill and downhill.

enter image description here

This sounds very simple. I searched around the web and found that this could be accomplished using the markov chain. I think this idea is really interesting.

You can create the first state of your scene by yourself and pass this state as input to the markov chain algorithm. The algorithm randomly changes this state and creates a walk.

However I cannot find any example of that algorithm and no source code. I just found an applet that demonstrates the markov chain algorithm: http://www.probability.ca/jeff/java/unif.html

Please suggest some code. Any other ideas how to accomplish this are appreciated too.

I painted an example

enter image description here

So I want the line to proceed in a similar way. There are valleys, slopes … they are random but the randomness still apply to the initial state of the line. This is why I found makrov chain so interesting here: http://www.suite101.com/content/implementing-markov-chains-a24146

  • 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-05-22T18:52:42+00:00Added an answer on May 22, 2026 at 6:52 pm

    Here’s some code in Lua:

    absstepmax = 25
    ymin = -100
    ymax = 100
    x = 0
    y = 5
    for i = 1, 20 do
        y = y + (math.random(2*absstepmax) - absstepmax - 1)
        y = math.max(ymin, math.min(ymax, y))
        x = x + 5
        print (x,y)
    end
    

    absstepmax limits the size of a y step per iteration

    ymin and ymax limit the extent of y

    There is no bias in the example, i.e., y can change symmetrically up or down. If you want your “drunk” tending more “downhill” you can change the offset after the call to random from absstepmax - 1 to absstepmax - 5 or whatever bias you like.

    In this example, the x step is fixed. You may make this random as well using the same mechanisms.

    Here are some sample runs:

    > absstepmax = 25
    > ymin = -100
    > ymax = 100
    > x = 0
    > y = 5
    > for i = 1, 20 do
    >>     y = y + (math.random(2*absstepmax) - absstepmax - 1)
    >>     y = math.max(ymin, math.min(ymax, y))
    >>     x = x + 5
    >>     print (x,y)
    >> end
    5   4
    10  22
    15  37
    20  39
    25  50
    30  40
    35  21
    40  22
    45  12
    50  16
    55  16
    60  12
    65  -1
    70  -8
    75  -14
    80  -17
    85  -19
    90  -25
    95  -37
    100 -59
    > absstepmax = 25
    > ymin = -100
    > ymax = 100
    > x = 0
    > y = 5
    > for i = 1, 20 do
    >>     y = y + (math.random(2*absstepmax) - absstepmax - 1)
    >>     y = math.max(ymin, math.min(ymax, y))
    >>     x = x + 5
    >>     print (x,y)
    >> end
    5   -2
    10  -15
    15  -7
    20  1
    25  1
    30  12
    35  23
    40  45
    45  43
    50  65
    55  56
    60  54
    65  54
    70  62
    75  57
    80  62
    85  86
    90  68
    95  76
    100 68
    > 
    

    Painted result added from OP:

    enter image description here

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

Sidebar

Related Questions

I'm making a game which has multiple planets. Now I want to randomly generate
i want to create a quiz application. the questions should be randomly selected from
Is there any way to randomly generate a set of positive numbers such that
I want when I shake my phone it randomly generate some no. I am
I want to generate array position from 1 to 1000 randomly using some mathematical
I want to generate random numbers within a range and the generated numbers should
Using Python I want to randomly rearrange sections of a string based on a
I have an ArrayList of strings, and I want to randomly change a string's
I'm creating a slider with 6 slides, and I want to randomly move between
I want to make an app that has a view that moves randomly or

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.