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

  • Home
  • SEARCH
  • 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 8576361
In Process

The Archive Base Latest Questions

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

I tried to do some sort of random generator – there are several adjacent

  • 0

I tried to do some sort of “random generator” – there are several adjacent points and depending on their brightness they are more or less likely to be chosen.

a point is an object with x and y coordinates and a bvalue, storing it’s brightness.

my approach was to set a p object (p for possibility) which has a start and an end value (both something between 0 and 1) – the difference between the start and the end value depends on their brightness.

I then generate a random number and loop through all points to see, whether the random number is between their start and end property. As one points start value is the previous point’s end value only one point should be chosen, but instead a random amount of points are chosen.

Thus I logged the random value and the points’ start and end properties. Looks like everything worked, except that the following code

for (i = 0; i < numAdjacentPoints; i++) {
    // set some shorthands
    curr_point = adjacentPoints[i];
    // if there is no previous point, we start with 0
    prev_point = ((i === 0) ? {p: {end: 0}} : adjacentPoints[i-1]);
    // initiate a probability object
    curr_point.p = {};
    // set a start value (the start value is the previous point's end value)
    curr_point.p.start = prev_point.p.end;
    // set an end value (the start value + the point's brightness' share of totalBrightness)
    // -> points with higher darkness (255-b) are more have a higher share -> higher probability to get grown on
    curr_point.p.end   = curr_point.p.start + (255 - curr_point.b) / totalBrightness;
    // if the random value is between the current point's p values, it gets grown on
    if (curr_point.p.start < rand < curr_point.p.end) {
        // add the new point to the path array
        path[path.length] = curr_point;
        // set the point's brightness to white -> it won't come into range any more
        curr_point.b = 255;
        console.log("  we've got a winner! new point is at "+curr_point.x+":"+curr_point.y);
        console.log("  "+curr_point.p.start.toFixed(2)+" < "+rand.toFixed(2)+" < "+curr_point.p.end.toFixed(2));
    }
};

outputs this:

we've got a winner! new point is at 300:132 mycelium.php:269
0.56 < 0.53 < 0.67 mycelium.php:270
we've got a winner! new point is at 301:130 mycelium.php:269
0.67 < 0.53 < 0.78 mycelium.php:270
we've got a winner! new point is at 301:131 mycelium.php:269
0.78 < 0.53 < 0.89 mycelium.php:270
we've got a winner! new point is at 301:132 mycelium.php:269
0.89 < 0.53 < 1.00

–> WTF? 0.56 < 0.53 < 0.67??

  • 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:54:28+00:00Added an answer on June 11, 2026 at 7:54 pm

    You want

    if (curr_point.p.start < rand  && rand < curr_point.p.end) {
    

    instead of

    if (curr_point.p.start < rand < curr_point.p.end) {
    

    You were comparing a number with the result of a comparison, that is a boolean. Your code was equivalent to

    if ((curr_point.p.start < rand) < curr_point.p.end) {
    

    and as a boolean is converted to 1 or 0 when used in such an operation, you were testing

    if (0 < 0.67) {
    

    operator precedence in javascript

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

Sidebar

Related Questions

I tried to make some sort of convenient class (below) to hold folder and
I tried some variants, one of them: tv.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence
I tried some add to favorties JavaScript scripts.. With IE8, I get an access
Just tried some small graphics application of mine on Windows 7, and I'm getting
I tried some codes but after it is send to mail account, it is
I've tried some codes like string s = this is example; txt1TextBlock.Text = Thread.CurrentCulture.TextInfo.ToTitleCase(s);
I've tried some tools for generate automatically class diagrams from the java source code
Possible Duplicate: Git: Revert to previous commit status I've tried some changes in my
I have google'd it, and tried some examples, but I always get stuck. This
I'm just curious to know about this.When i heard about Spring.net and tried some

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.