Weekly Qbasic and Qb64 Lesson Topics
October 22, 2018, 10:25:18 pm
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Want to see a specific Tutorial? ASK!
  Home Help Search Arcade Links Staff List Login Register  

Chance(n) function

Pages: [1]
Author Topic: Chance(n) function  (Read 239 times)
Post Demos
Posts: 14

« on: June 26, 2011, 11:04:58 am »

[Wow, I just found out one shouldn't use the tab key much in posting here-- got kicked out of the editor]

Hi (again),

The Chance(n) function is obviously related to the RndRange() routine I posted before and, while I don't use it as often, it does have its uses.  Here is something similar to some code I was playing with last night in which I caused increasing chances of a wandering character to change course:

Odds = 1 ' 100% chance
  ...some plain code...
  IF Chance(Odds) then
    ...some special code...
    Odds=20 'switch to happening only 5% of the time
  end if
  ...more plain code...
  Odds = Odds - 1 'Increase the chance of something special happening down toward 100% chance
FUNCTION Chance%(n%)
  Chance% = (RND * n%) < 1  ' gives 1 chance of TRUE out of n possibilities

Report Spam   Logged

Social Buttons

« Reply #1 on: June 26, 2011, 11:28:39 am »

Hi all,
    Tanks Quark , nice function. Will come in handy in games i think.
Report Spam   Logged

Pages: [1]
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum

Buy traffic for your forum/website
Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy