Random Equation With Specifics
My mind is mush today thinking about all of the new MMF2 features. I've been toying around with equations all morning trying to find one that can only yield the answers 4,6,8,9. Can anyone tell me an equation using the Random() function that will only produce one of those numbers?
Re: Random Equation With Specifics
val(Mid$("4689", Random(4), 1))
If you need me to explain why it works I can.
Re: Random Equation With Specifics
That's an amusingly ingenious solution.
:)
Re: Random Equation With Specifics
Quote:
Originally Posted by Dynasoft
That's an amusingly ingenious solution.
:)
Thank you.
Re: Random Equation With Specifics
I wish i could understand that equation... hehe ^_^
Re: Random Equation With Specifics
Very clever indeed !
@cocodrillo : what he's doing isn't maths, he's just picking one character in the "4689" string, using Mid(str,firstchar,length).
Re: Random Equation With Specifics
Ahaha, i've come across this problem once or twice before and yes, that is an amazing solution! Wish i'd thought of that before!
Re: Random Equation With Specifics
Corentin is correct.
[font:Courier New]val(string)[/font]: Converts a string to a number.
[font:Courier New]Mid$(string,start position,length)[/font]: "Extracts a sub string starting at a given position. Example, MID$("Hello", 2, 3) will return "ell"."
[font:Courier New]Random(maximum value)[/font]: "Retrieves a random number. The parameter you specify determines the maximum value of the random number."
--------
[font:Courier New]val(Mid$("4689", Random(4), 1))[/font]
Generates a random number between 0 and 3.
[font:Courier New]val(Mid$("4689", Random(4), 1))[/font]
Uses the generated number to decide starting position and therefore which character to extract from the sub string (only 1 character is returned because length is 1). If the random number was 0 then it'd be the same as Mid$("4689",0,1) which gets the first character. Using this method every randomly generated number is effectively mapped to a character in the string.
[font:Courier New]val(Mid$("4689", Random(4), 1))[/font]
Converts the randomly chosen character from a string to a number.
Re: Random Equation With Specifics
That is quite amazingly simple. Turning them into a string and back into a number. I had been trying all sorts of things like (Random(2)+2)*(Random(3)+1) and all sorts of weird things. I had done something like that in the past for an encoder. I used the ASCII function of the string parser to turn each letter of a phrase into a number, add a couple values to it, and turn it back into letters again. Your method could come in handy for a lot of other things too.
Re: Random Equation With Specifics
Quote:
Originally Posted by Cocodrilo
I wish i could understand that equation... hehe ^_^
ye same....