Random only returning one result

Started by Chadderbox on

Topic category: Help with modding (Java Edition)

Last seen on 17:18, 6. Mar 2020
Joined Jul 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Random only returning one result
Sat, 02/29/2020 - 09:25 (edited)

The following procedure is supposed to return a number between 1 and 0, and then X it by 10 to make it a number between 1 and ten, yet it only returns a Gold Nugget. Could someone help me?

I haven't put this in bugs as I think it may be my stupidity with logic, and also after looking at the code, it is exactly what I would write (Math.random() * 10), so I have no clue what is going on here.'

 

The Procedure
Here is the procedure

 

Edit for if the image doesn't work: https://imgur.com/a/I3kTpQw

Edited by Chadderbox on Sat, 02/29/2020 - 09:25
Last seen on 14:12, 3. Jun 2023
Joined Nov 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The "anotherNum" variable…
Sat, 02/29/2020 - 11:14

The "anotherNum" variable isn't rounded, so it can have values between two integers too (for example, 2.3 or 7.6). This means it's almost impossible for it to be exactly 7. There should be a block under math with a "floor" operation: it rounds your random number to the integer right below, so its possible values will be exactly 0, 1 ... 9.

Another thing that isn't related is that the "else if number <= 8" is unnecessary: at that point the number is already <= 7, so a simple "else" is enough

Last seen on 17:18, 6. Mar 2020
Joined Jul 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thanks! That helps a lot, I…
Sat, 02/29/2020 - 12:20

Thanks! That helps a lot, I knew it was me being stupid! I should have looked more into the code.