Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / How to make random occurence base on percentage?

Author
Message
hoyoyo80
7
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 15th Mar 2017 18:46
Hi all,

I know there is a command for random but i want to know how to implement random base on percentage like accuracy 70% hit 30 % miss. Can someone shed me some light?Thanks
Increase
7
Years of Service
User Offline
Joined: 21st Feb 2017
Location:
Posted: 15th Mar 2017 18:51 Edited at: 15th Mar 2017 18:52
you can do a = random (1,100)

If a < 30 then gosub miss
If a > 30 then gosub hit
hoyoyo80
7
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 15th Mar 2017 19:03
Thanks for quick reply, its so simple
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th Mar 2017 19:09
What if it rolls 30 exactly?

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Increase
7
Years of Service
User Offline
Joined: 21st Feb 2017
Location:
Posted: 15th Mar 2017 19:11
If a = 30 then gosub superspecialshotyeah
hoyoyo80
7
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 16th Mar 2017 07:43
Is there any big difference if i divide into two category 1 hit 2 miss and make a range like 1-10, 30-40 and 90-100 is 2 that is miss?
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 16th Mar 2017 09:23
No it just means a little more coding



However, and this is what Phaelax was talking about, there is no resolution for number between 10 and 30 or between 40 and 90 so what would you want to do? You need to make sure that there is a proper resolution for all values of a.

If I was doing this for a role playing game, for example, I might do something like this:


Hover Car Race Challenge! - available now on Google Play
Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB
Quell Dieu
7
Years of Service
User Offline
Joined: 8th Feb 2017
Playing: Genres: Action, MOBA, FPS, Fighting, TBS, RTS, Puzzle.
Posted: 16th Mar 2017 14:40 Edited at: 16th Mar 2017 14:43
84 = critical miss XD


Quote: "
"

the first code snip doesnt always display sometimes its blank
Playing Codes from Documentation
hoyoyo80
7
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 17th Mar 2017 03:46
Thanks for the answers

OT: the forums need a better emo icons. Wheres thumbs up? Hihi
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 17th Mar 2017 11:03
Quote: "the first code snip doesnt always display sometimes its blank"


Yes, this was deliberate. I probably should have emphasized this more as it was to illustrate the need to make sure that all possible outcomes are dealt with properly.

@hoyoyo80: glad you've found this useful.
Hover Car Race Challenge! - available now on Google Play
Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB

Login to post a reply

Server time is: 2024-04-23 00:32:39
Your offset time is: 2024-04-23 00:32:39