Weekly Qbasic and Qb64 Lesson Topics
July 18, 2018, 07:38:48 am
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]
  Print  
Author Topic: Chance(n) function  (Read 237 times)
Quark
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
DO
  ...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
LOOP
END
'----------------------------------------
FUNCTION Chance%(n%)
  Chance% = (RND * n%) < 1  ' gives 1 chance of TRUE out of n possibilities
END FUNCTION

--Quark
Report Spam   Logged

Social Buttons

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

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

Pages: [1]
  Print  
 
Jump to:  

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

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