Random Function and Decimal values

I'm trying to have random colors assigned to an object, but I'm finding that's not possible due to the Random function not accepting decimal values and placing random(0,1) only chooses 0 or 1. This wouldn't be an issue if you could simply place an integer value for the Red, Green, and Blue values for the color of an object, instead we're left with equating the value you want for each RGB value as a decimal.

Anyway, my point being.. can anyone prove me wrong that the Random function does in fact accept decimal values and I'm just doing something wrong?

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2012
    You're not wrong, but there's an easy workaround:

    Change Attribute self.color.Red to random(0,10)/10

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    @RacetotheMoon

    Hi, the Random expression doesn't cater for decimal values; positive integer values only.

    So for a solution of a generated random decimal, I suggest something like the following:

    (it's probably more watertight to change a real attribute and then use that as the chosen random value) In this example, it'll be for three decimal places:

    Change Attribute RandColR to Random(111,999)/1000
    Change Attribute self.Color.Red to RandColR

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2012
    You're not wrong, but there's an easy workaround:

    Change Attribute self.color.Red to (0,10)/10
    (0,10)/10 would only give you 1,000 colours out of a possible 16,777,216.

    Change Attribute RandColR to Random(111,999)/1000
    This equation clips off the bottom 11.1% of available colours - and at the top - it clips off pure white (not that anyone would notice the difference between .999 and 1).


    Each colour channel is 8bit, the calculation should be: Change Attribute self.color.Red to random(0,255)/255






  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2012
    DP
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Sorry, I was just writing a generic Change Attribute self.Random to random(0,10)/10 to give the idea that you could generate decimals from 0 to 1, but then I threw in self.color.Red at the last moment to make it more relevant (and apparently, wrong!). Thanks.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Member Posts: 12,822
    Sorry, I was just writing a generic Change Attribute . . . .
    Sorry is not good enough, the number gods will be angered, watch out for lightening storms over the next couple of days.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited December 2012
    <


    Each colour channel is 8bit, the calculation should be: Change Attribute self.color.Red to (0,255)/255
    Hi @Socks I understand your reasoning re: 0 to 255, but the value type required for the Color attributes in GSC is in the range of 0 to 1.

    So @tatiang is correct in his example to generate in one decimal place, (albeit a limited amount of colours); mine is as close as you can get with three decimal places (actually, I've just thought, a bit closer at the zero end: Random(100,999)/1000 )

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2012
    Hi @Socks I understand your reasoning re: 0 to 255, but the value type required for the Color attributes in GSC is in the range of 0 to 1.
    Whoops, I missed the word 'random' out, my calculation should have read Change Attribute self.color.Red to random (0,255)/255.
    tatiang is correct in his example to generate in one decimal place, (albeit a limited amount of colours); mine is as close as you can get with three decimal places (actually, I've just thought, a bit closer at the zero end: Random(100,999)/1000 )
    Tatiang's method reduces the amount of colours the calculation generates from the available 16,777,216 to just 1,000.

    Your new method loses the 'bottom' 10% of all colours as well as pure white at the 'top' (1,1,1).

    Random(0,255)/255 will give you all 256 colours (8bit) for each channel (or 16,777,216 / 24bits) when applied to all three channels.
  • RacetotheMoonRacetotheMoon Member Posts: 323
    Well done, Gents. Thanks for the knowledge. =D>
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited December 2012

    Hey @Socks, I see what you mean now... :-) I will flay my back immediately with a horsehair whip! Spot on, and worth remembering, thanks.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • SocksSocks London, UK.Member Posts: 12,822

    Hey @Socks, I see what you mean now... :-) I will flay my back immediately with a horsehair whip! Spot on, and worth remembering, thanks.
    It's too late, your name is already on 'the list' right under Tatiang's, come the great math robot uprising of 2013 you will be sent to a regional reprogramming camp.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598


    It's too late, your name is already on 'the list' right under Tatiang's, come the great math robot uprising of 2013 you will be sent to a regional reprogramming camp.
    aaaaaaaah..............phooey. :o3

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2012

    aaaaaaaah..............phooey. :o3
    @gyroscope

    Here's the maths in action:

    http://www.mediafire.com/?bo8835830d9oy67
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    Hi @Socks that is Wow indeed! Thanks, I'm much impressed with that! :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2012

    Hi @Socks that is Wow indeed! Thanks, I'm much impressed with that! :-)
    There's a second colour way set up (in actor 'B') which I prefer.

    Takes you a bit more into the mid 1970s. : )

    Like this: http://www.mediafire.com/?wmz323k94kr9z4d
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2012
    I never liked those other 16,776,216 colors. :P

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.