Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: 4ppleseed on February 12, 2017, 05:12:20 PM

Title: How do I make Random Float always end on an ODD number?
Post by: 4ppleseed on February 12, 2017, 05:12:20 PM
Hi all,
I saw on the Ecosystem there is a Random INT odd/even.

What I need is to make a float that always ends in an odd number. So 1.1 2.1 3.1, 1.3 2.3 3.3, 1.5 2.5 3.5, 1.7 2.7 3.7 etc would all be acceptable.

Any ideas for making a Random Float range between -5.0 and 5.0, always end on an ODD number?

Thanks  8)
Title: Re: How do I make Random Float always end on an ODD number?
Post by: midgear on February 12, 2017, 06:18:40 PM
One ugly way of doing it is using an "Int Switch" where you manually input the even numbers in your range. Then send said even numbers to a send event that will add +1 then have it go back into the "Int Switch" where there is odd number send event that goes to the rest of your script.

Then do a convert to float.

(http://mockgirl.com/wp-content/uploads/2017/02/EvenOdd.png)

Title: Re: How do I make Random Float always end on an ODD number?
Post by: 4ppleseed on February 13, 2017, 04:07:04 AM
Yeah, I tried something like this but you can't then combine two INTS into a float.

Lets say I do Random INT and get 2
Then do another Random INT and get 4, which a reroll until ODD so then get 5

How would I combine the INT 2 and the INT 5 to make the FLOAT 2.5

I need to be able to generate a FLOAT with one decimal place that is always ODD.

1.5, 2.9, 3.1, 4.7, 5.3 etc...
Title: Re: How do I make Random Float always end on an ODD number?
Post by: 600 on February 13, 2017, 04:16:14 AM
Get random int #1, convert to float.
Get random int #2.
Convert int #2 to float and divide with 10, you get 0,x
Then float #1 + the new float #2.
Title: Re: How do I make Random Float always end on an ODD number?
Post by: 4ppleseed on February 13, 2017, 10:33:04 AM
Get random int #1, convert to float.
Get random int #2.
Convert int #2 to float and divide with 10, you get 0,x
Then float #1 + the new float #2.

That won't guarantee the last digit is an ODD number, will it?
 
Title: Re: How do I make Random Float always end on an ODD number?
Post by: 600 on February 13, 2017, 11:14:09 AM
Oh… yeah I missed that part in the morning  ;D
Then I don’t know..
Title: Re: How do I make Random Float always end on an ODD number?
Post by: marv on February 13, 2017, 11:27:41 AM
Combining 600's and midgear's approaches would let you do it. Another kind of messy approach would be to

- convert the float into a string
- take the last character of the string ("string take n from right" is what it's called iirc)
- convert it into an int
- test it for even/odd
 -> proceed with float if true
 -> get next float if false

I can't think of any currently available actions that would let you do this in a neat/tidy way.
Title: Re: How do I make Random Float always end on an ODD number?
Post by: 4ppleseed on February 15, 2017, 11:59:52 AM
Thanks for your help - I actually gave up in the end haha.

I managed to sorta get it to work by adding a pixel to the sprite then using round to nearest 0.2 which then makes the float EVEN - which I can now use to line things up.