How do I generate a random dollar value

0 favourites
  • 6 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • Hi.

    I am creating a game to help my son with money / change. I want to generate a random total for the 'shopping' between $1.00 and $10.00. The generated value must have a 5c resolution, i.e. $2.75, $6,20, etc. Something like $4.22 would not be valid. The aim is to pick from currency images to create the correct change.

    It has been a while since I did any dev, so I am struggling with the structure of the required random() function.

    Thanks - AC

  • 1st method

    1) make images of currency coins say 0.05,0.10,0.25,0.50,1,2,5.

    2) then pick coins and make a big number

    2nd method

    generate random number between 100($1),1000($10) then divide by 5(5c resolution) and store in "aaa" then multiply "aaa" by 5 then divide by 100 to get the $xx.xx value

  • Thanks I want to use the second method, but it still genarates numbers like this: 5.812518740331899, using this formula: ((random(100,1000)/5)*5)/100.

    Cheers - AC

  • It was too hard! I used this instead:


  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • But it displays "1" instead of "1.00" and "1.2" instead of "1.20", etc. Grrr.

  • SOLVED!! I changed all my choose() values to 1.001, 1.201, etc, then used this formula to grab 2 decimal places:

    left( str(<the choose() number>), find( str(<the choose() number>), ".")+3)

    Thankyou Dan72 and this post:

    Cheers - AC

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)