# Random % Chance?

Is there a way to have certain random items appear more often or less often using a percent of chance? For example: I have a common item I want to appear 1 out of 3 times, and a rare item appear 1 out of 50 times.

Thank You
InsertCoin25

|| Do = Random(3) to variable r

(sub event)

Variable r = 0; || Create object one_in_three

And…

|| Do = Random(50) to variable r

Variable r = 0; || Create object rare_item

Can this also be applied to an array? Thank you for the reply, Mats.

InsertCoin25

Not sure what you mean by that?

I am doing the Memory Match Tutorial, and was wondering during the shuffling of cards, if certain cards can be picked 1/3 of the time and certain cards can be picked 1/50 of the time (common and rare cards). In the tutorial they are using arrays. I could be completely misunderstanding what is going on with the shuffle, so if that is the case I apologize for the confusion.

Thank You
InsertCoin25

If you want to simulate decks of cards, there are many options.

-You could make a structure and have the cards as children. Each card would appear as many times as it would appear in the deck (basically equivalent to the array method).

-You could use random numbers and adjust them so for card rarity e.g.

[code]new_card = Random(1000);

new_card < 100 || Create object card_10pc

new_card >=100 || Create object card_70pc
new_card <800

new_card >= 800 || Create object card_18pc
new_card < 980

new_card >980 || Create object card_2pc[/code]

-In a native project, you can link and use C++ containers for cards.

Basically, there are tons of ways to deal cards. It can be applied to anything.
Mats is only showing you how to calculate the probability, what you do with that number is not included in your question or his answer.

I suggest this formula to get a random number between two specific numbers:

``Random(Variable(upper_bound)-Variable(lower_bound))+Variable(lower_bound)``

Where:

lower_bound — is the lowest possible number
upper_bound — is the highest possible number

Example:

lower_bound = 5
upper_bound = 10

random_number = Random(10-5)+5

The result (stored in the variable random_number) can be any number in this set: {5,6,7,8,9,10}

You can build a function in GD and pass the lowest and highest numbers as parameters, to use it recursively and evade the task of rewrite the formula every time you need to use it in your events.

Thank you Mats and erdo for the help. I am going to try and implement this and let you know how it goes. Thank you again.

InsertCoin25