Hello, I`m trying to get a random value between a negative comma value and a positive (comma) value.
For example between -2.5 and 1.5.
I can use for this:

B-A→C            //C=difference of A and B
A+rand*C→R       //R=random value between A and B

But this is not very efficient (especially in a loop which should work fast),
so does somebody know how to make it better?
Is it possible to use just one command and I missed something?
SOLUTIONS: (found help at the chat)

If your program alredy has stored A and B (or what variables you need),
this command line will work pretty good:


If your values are constant, you won`t need to store them extra as variables to use them in the command line descibed above. You just put the values in the code from above:

-2.5+rand*(1.5- -2.5)→R

or better:


You can also do this:


it will work of course too with values with
more than 1 digit behind the comma:

//example values: -17,70731 and 17.70731


And don`t forget: this routines work also with two negative or two positive values!
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum