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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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:

    choose(1.00,1.05,1.10,1.15,1.20,1.25,1.30,1.35,1.40,1.45,1.50,1.55,1.60,1.65,1.70,1.75,1.80,1.95,2.00,2.05,2.10,2.15,2.20,2.25,2.30,2.35,2.40,2.45,2.50,2.55,2.60,2.65,2.70,2.75,2.80,2.95,3.00,3.05,3.10,3.15,3.20,3.25,3.30,3.35,3.40,3.45,3.50,3.55,3.60,3.65,3.70,3.75,3.80,3.95,4.00,4.05,4.10,4.15,4.20,4.25,4.30,4.35,4.40,4.45,4.50,4.55,4.60,4.65,4.70,4.75,4.80,4.95,5.00,5.05,5.10,5.15,5.20,5.25,5.30,5.35,5.40,5.45,5.50,5.55,5.60,5.65,5.70,5.75,5.80,5.95,6.00,6.05,6.10,6.15,6.20,6.25,6.30,6.35,6.40,6.45,6.50,6.55,6.60,6.65,6.70,6.75,6.80,6.95,7.00,7.05,7.10,7.15,7.20,7.25,7.30,7.35,7.40,7.45,7.50,7.55,7.60,7.65,7.70,7.75,7.80,7.95,8.00,8.05,8.10,8.15,8.20,8.25,8.30,8.35,8.40,8.45,8.50,8.55,8.60,8.65,8.70,8.75,8.80,8.95,9.00,9.05,9.10,9.15,9.20,9.25,9.30,9.35,9.40,9.45,9.50,9.55,9.60,9.65,9.70,9.75,9.80,9.95,10)

  • 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)