Results 1 to 8 of 8

Thread: RandomPercent

  1. #1
    Danya82's Avatar Tiro
    Join Date
    Oct 2010
    Location
    Saint-Petersburg, Russia
    Posts
    227

    Default RandomPercent

    As i understand, if RandomPercent > 50 (for example), it not to mean that something will be generated with 50%, it mean that percent will be generated from 51 to 100, and something will be generated with this generated percent, am i right?

  2. #2
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: RandomPercent

    RandomPercent generates a random number between 0 and 100 (inclusive). > 50 tests to see if that generated number is 51 or higher.

    http://www.twcenter.net/forums/showt...1#post15249717

  3. #3
    Danya82's Avatar Tiro
    Join Date
    Oct 2010
    Location
    Saint-Petersburg, Russia
    Posts
    227

    Default Re: RandomPercent

    I mean that some event, if RandomPercent > 50, will have a chance > 50% (for example 60%), if RandomPercent < 50, will have a chance < 50% (for example 40%), is it right?

  4. #4
    Danya82's Avatar Tiro
    Join Date
    Oct 2010
    Location
    Saint-Petersburg, Russia
    Posts
    227

    Default Re: RandomPercent

    That's the example from script:

    Code:
    if I_SettlementOwner Barcelona = portugaland not I_SettlementUnderSiege Barcelona
    and not I_CharacterExists Carlo
    and RandomPercent < 6
    and RandomPercent < 51
    and I_CompareCounter Barcelona = 0
    historic_event Rebels_attack
    set_counter Not_two_times 1
    set_counter Barcelona 1
    end_if
    I can't understand why there are 2 same conditions

  5. #5

    Default Re: RandomPercent

    RandomPercent is terrible, don't use it in the script (you don't have any other choice in the EDCT); generate_random_counter is better. The latter reliably self-resets, the former does not.

    The latter will also create an event_counter that can be used for all sorts of things.

  6. #6
    Danya82's Avatar Tiro
    Join Date
    Oct 2010
    Location
    Saint-Petersburg, Russia
    Posts
    227

    Default Re: RandomPercent

    The problem is that i'm redacting some mod for yourself, and there are used RandomPercent, so i wanna just know, if, for example RandomPercent < 50, it means that some random percent from 0 to 49 will be generated, for example, 35%, and with this chance event may happens. Or any generated integer from 0 to 49 will give 100% result that event happens.

  7. #7
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: RandomPercent

    RandomPercent < 50 does not generate a number between 0 and 49. It generates a number between 0 and 100. Always. Whatever that number happens to be, there is a 50% chance that it is less than 50, and 50% chance that it's greater, therefore RandomPercent < 50 and RandomPercent > 50 both mean 50% chance that the event happens.

    If you want something to happen only 35% of the time then use either RandomPercent < 35 or RandomPercent > 65. If you want a 10% chance then use either RandomPercent < 10 or RandomPercent > 90.

    In other words, RandomPercent < 50 does not mean "generate a random number that is less than 50". It means "generate a random number (between 0 and 100) and if that number is less than 50 then this condition evaluates to TRUE".
    Last edited by Withwnar; September 20, 2019 at 03:23 AM.

  8. #8
    Danya82's Avatar Tiro
    Join Date
    Oct 2010
    Location
    Saint-Petersburg, Russia
    Posts
    227

    Default Re: RandomPercent

    Ok, the question is closed, thanks Withwnar, if you may be yet look at my economy script and check it for the mistakes, i would be very appreciated for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •