This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Coding probability

Old posts that have not been replied to for several years.
Locked
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Coding probability

Post by ^DooM^ »

Hey guys merry xmas.

Need a hint on how to code probability

Instead of just using rand to choose wether something is executed or not im looking for a way to give it say a 1 in 20 chance of being executed rather that a 1 in 2 chance. I did a search for probability but came up empty.

Any help would be greatly appreciated.

Thanks again.

Jon.
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

Code: Select all

if ![rand 20] {yourproc}
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

Code:

if ![rand 20] {yourproc}
OMG i am so dumb at times

thanks demond please dont hesitate to laugh at my stupidity :)
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

[expr [rand 20] +1]
Once the game is over, the king and the pawn go back in the same box.
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

@caesar: that's needed if he wants numbers from 1 to 20. but if he just wants a 1 of 20 chance, demond's solution is fine :)
aVote page back online!
Check out the most popular voting script for eggdrop bots.

Join the metal tavern!
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

The result of [rand 20] will allways be a number betwen 0 and 19 (0 and 19 included), while the result of [expr [rand 20] +1] will be from 1 to 20 (1 and 20 included). And if you read again he did said 1 to 20 not 0 to 19. :P
Once the game is over, the king and the pawn go back in the same box.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

caesar wrote:The result of [rand 20] will allways be a number betwen 0 and 19 (0 and 19 included), while the result of [expr [rand 20] +1] will be from 1 to 20 (1 and 20 included). And if you read again he did said 1 to 20 not 0 to 19. :P
0 to 19 are exactly 20 numbers, hence 1 in 20 8)
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Nevermind. You haven't got my "1 to 20" point.
Once the game is over, the king and the pawn go back in the same box.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

<snip>
XplaiN but think of me as stupid
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

lol

Post by ^DooM^ »

Hey guys

All i needed was a small easy way to make my bot kick someone with a 1 in 20 chance of them triggering the proc kinda a russian roulette thing so 0 - 19 or 1 - 20 would do exactly the same thing at the end of the day thanks again for your replys :) hope you all had a good xmas. :wink:
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

caesar wrote:The result of [rand 20] will allways be a number betwen 0 and 19 (0 and 19 included), while the result of [expr [rand 20] +1] will be from 1 to 20 (1 and 20 included). And if you read again he did said 1 to 20 not 0 to 19. :P
that's exactly what i meant ;)
however, he didn't say "1 to 20", he said "1 in 20" (chance), so if you take 0-19 or 1-20 doesn't matter :)
aVote page back online!
Check out the most popular voting script for eggdrop bots.

Join the metal tavern!
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Re: lol

Post by Ofloo »

^DooM^ wrote:Hey guys

All i needed was a small easy way to make my bot kick someone with a 1 in 20 chance of them triggering the proc kinda a russian roulette thing so 0 - 19 or 1 - 20 would do exactly the same thing at the end of the day thanks again for your replys :) hope you all had a good xmas. :wink:
easyest way is to use switch

Code: Select all

switch  -- [rand 20] {
  "0" {
    # code 
  }
  "1" {
    # code 
  }
  "2" {
    # code
  }
  #... i gues you get the picture ..
}
or ..

Code: Select all

switch  -regexp [rand 20] {
  "(0|3|6)" {
    # code 
  }
  "(1|4|7)" {
    # code 
  }
  "(2|5|8)" {
    # code
  }
}
if you don't have that mutch conditions.. to shorten the code.. don't see the use but hell..
XplaiN but think of me as stupid
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

aye your way is great if i wanted to execute something different on a number returned but all i wanted was something to be executed with a 1 in 20 chance which [!rand 20] did perfectly cheers :)
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

sorry right i missed the ! which in this case is verry important .. hehe also if that is the case i have to say u can't use the +1 method cause it will never return 0 = > if the value is 1-20 the if statement will never be true ..
XplaiN but think of me as stupid
Locked