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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:42:19+00:00 2026-05-19T01:42:19+00:00

newValue := oldValue; repeat delta := (RandomRange(0, 200) / 100) – 1; newValue :=

  • 0
newValue := oldValue;
repeat
    delta := (RandomRange(0, 200) / 100) - 1;
    newValue := newValue + delta;
 until (newValue > 24) and (newValue < 40);
 oldValue := newValue;


newValue2 := oldValue2;
repeat
    delta := (RandomRange(0, 200) / 100) - 1;
    newValue2 := newValue2 + delta;
 until (newValue2 > 24) and (newValue2 < 40) and (newValue2 < newValue); 
 oldValue2 := newValue2;

after a few iterations, this hits an endless loop in the second loop. It is meant to change a Float randomly by -1 to +1 and keep it in the range 24 to 40 while still being less than another Float which is being randomly changed in the same way.

Who can be first to make me say “d’oh!”? (probably by (newValue2 < newValue))


d’oh!

Well, now that it is pointed out, the answer is obvious. newValue := oldValue + delta;, not ` newValue := newValue + delta;’, so that the code reads (similar for both loops)

newValue := oldValue;
repeat
    delta := (RandomRange(0, 200) / 100) - 1;
    newValue := oldValue + delta;              <==== **NOT**  newValue
 until (newValue > 24) and (newValue < 40);
 oldValue := newValue;

Thanks, all, and lots of +1 all round

  • 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-19T01:42:20+00:00Added an answer on May 19, 2026 at 1:42 am

    What do you mean by “keep it in the range 24 to 40”? Your condition “until (newValue > 24) and (newValue < 40)” implies that it will stop once it is in that range; it will go forever if it is outside that range.

    The chances of it terminating depend upon oldValue. What values are you expecting oldValue to have?

    In any case, such a loop is not guaranteed to terminate. You are changing the number randomly each time, so there is no guarantee it will move into the termination range at all. In particular, a large number of random numbers between -1 and 1 all added together will usually sum to approximately 0, so you can’t expect the number to change significantly over time. It’s probably the case that it happens never to enter that range.

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

Sidebar

Related Questions

I have the following html: <html> <head></head> <body> <form> <input id=msg type=text value=oldValue />
I have an xml document as follows <users> <user test=oldvalue> <userid>sony</userid> <name>vijay</name> </user> </users>
I'm not sure if I'm phrasing this in the best way but I have
I need to update a combobox with a new value so it changes the
The method Concat() does not modify the original value. It returns a new value.
My company needs to write a query that determines when data is being entered
I have a table that stores a value that will be added to over
I have a view in SQL server that translates from one schema version to
I'm in the process of learning WPF coming from WinForms development. I have a
It occurs to me that if you have fields dependent on each other in

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.