x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Best way to determine chance?

I have been using a method of determining chance that basically has an integer that is random and then if that number is higher than the target integer, do something. I want to know if there is a better way of determining chance by percentage. I see the integer percentage node but I am unsure how it works. So if I wanted something to happen 10% of the time, right now I would do random integer between 1-10 and if the number is equal to 1 let the event happen. Is there another way to achieve this?

Product Version: Not Selected
Tags:
more ▼

asked Mar 28 '15 at 11:35 PM in Blueprint Scripting

avatar image

VigeoJames
116 34 28 42

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

5 answers: sort voted first

To determine if something should happen based on percentage:

IN C++ :

 bool ShouldHappen(int percentage)
 {
     return (FMath::RandRange(1, 100/percentage)==1?true:false);
 }

In Blueprints: http://img.ctrlv.in/img/15/03/29/55174569468f0.png http://img.ctrlv.in/img/15/03/29/5517462b21205.png http://img.ctrlv.in/img/15/03/29/551746464820a.png

  • If the input value is 100 then there is 100% chance that it should happen.

  • If the input value is 50 then there is 50% chance that it should happen

  • and so on..

more ▼

answered Mar 28 '15 at 11:53 PM

avatar image

Azarus
1.9k 61 52 191

avatar image VigeoJames Mar 29 '15 at 12:02 AM

Nice, thank you. I should be able to implement something like this.

avatar image Azarus Mar 29 '15 at 12:03 AM

You can create a blueprint function library and create a function so its simpler to reuse :)

avatar image VigeoJames Mar 29 '15 at 12:14 AM

I see it has to do with C+ to actually make a blueprint function library. I know I could do it but it is unknown territory right now. If you know of any tutorials on how to do this that would be great. :D

avatar image Azarus Mar 29 '15 at 12:28 AM

No you don't need c++ to do function libraries! I updated my answer!

avatar image VigeoJames Mar 29 '15 at 01:30 AM

Awesome! Thanks!

avatar image chriis.aburto Nov 18 '15 at 11:02 PM

@Azarus im curious on how the

bool ShouldHappen(int percentage); { return (FMath::RandRange(1, 100 / percentage) == 1 ? true : false); }

would work because wouldn't there be errors in the code? so lets say in the .h file you have bool ShouldHappen;

and in the cpp you structure it that way

bool ShouldHappen(int percentage); { return (FMath::RandRange(1, 100 / percentage) == 1 ? true : false); }

Im asking because im getting errors and having trouble getting this to work, basically i want a 33 percent chance of a health pickup spawning

avatar image chriis.aburto Nov 19 '15 at 10:24 PM

errors as in trying to return a value in void function

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

there also an option to do this with 'Random Bool with Weight': alt text

chance_bool.png (36.1 kB)
more ▼

answered Sep 01 '16 at 01:34 PM

avatar image

Pirog
85 7 12 16

avatar image TextusGames Jul 06 '18 at 07:18 PM

thank you it works well enough for me.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Is there a better way to determine this because this is broken.. anything over a 50% chance becomes 100%

more ▼

answered Aug 10 '16 at 04:56 PM

avatar image

alucardddd
1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

bool ShouldHappen(int Percentage ) { return (FMath::RandRange(1, 100) <= Percentage ? true : false); }

This should yield all values from 1 to 100% chance

more ▼

answered Mar 13 '18 at 11:45 AM

avatar image

goldenphoenixdbr
1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

alt text

capture.png (82.9 kB)
more ▼

answered Oct 25 '18 at 08:30 PM

avatar image

ThatsShocking
23 3 5 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question