Random (0,1) behavior incorrect?

Published by smmmadden on Sun, 01/20/2019 - 21:11
Status
Works as designed
Type
Product/platform
MCreator/Windows
Priority
Normal
Issue description

In the image below, I'm checking to see if the player has broken the dark emerald block and is picked up.  Then I wanted to drop an emerald with a 50% chance in getting an emerald on the block break event that calls this procedure.

Using random for block break/drops

I've tried many combinations with X, + and what I'm seeing is the formula above skips the first block break and gives no emeralds.  Then every block thereafter I get one emerald with the block.  If I change the second digit to say 5, I get a random number of emeralds every time (1, 4, 2, etc.) which is also not what I want.

What I'm trying to add (failing miserably) is just the % chance in getting the emerald and to NOT give one predictably after breaking 1 block.  I'm sure I'm doing something wrong here, so could you tell me what I'm missing?  Thanks -Steve

Issue comments

I finally found the right logic to do what it needed, but it's not exactly what I would have thought I'd need.  Reading it, it sounds like If the entity received a dark emerald in inventory, do "if random (0,1) < 0.3" do add 1 emerald. To me a "do if" suggests that the condition that follows was already instantiated and available, but in my case it is not.  Regardless though, this does give the player a 30% chance in getting an emerald.  I found it under the Template Library under "Do with 70% chance".  Is there a reason why the extra if/do is needed?

random logic working

This is how programming works and we made this similar to programming so using procedures one can enter the programming.

Syntax of if block in Java is this:

if (boolean variable) {

}

And this boolean variable is a logic value. In your case, this logic value is the result of the < comparison block.



Donate to MCreator

By donating to developers you can speed up development, as with more resources, we can dedicate more time to MCreator. It is a free project made by developers working on it in their free time.