Jump to content
Sign in to follow this  
gil900

I want to do something .. Please help me.

Recommended Posts

gil900

hello,

i want to do something very specific and strange ..

look what i want to do:

for example i have:

case a - 20% Likely to happen

case b - 50% Likely to happen

case c - 30% Likely to happen

in this example i want that case b will most occur because it occupies the highest percentage.

next, case c will happen but less then case b.

case a will occur least.

if i have only one case( only case a) so only case a will occur..

I do not know where to start for write this.

Thank for helpers :)

Edited by gil900

Share this post


Link to post
Share on other sites
trancexx

Ducks go quack and fish go blub and the seal goes ow ow ow... What does the fox say?

- Ring-ding-ding-ding-dingeringeding!? Gering-ding-ding-ding-dingeringeding!?!

Nope?

You should try harder explaining what you want to do. Something that makes sense to you doesn't have to make sense to other people.

  • Like 2

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
gil900

Ducks go quack and fish go blub and the seal goes ow ow ow... What does the fox say?

- Ring-ding-ding-ding-dingeringeding!? Gering-ding-ding-ding-dingeringeding!?!

Nope?

You should try harder explaining what you want to do. Something that makes sense to you doesn't have to make sense to other people.

Sorry. I'll try to explain myself better.

My English is not the native language so I'm sorry

Share this post


Link to post
Share on other sites
gil900

I have the following table:

text1 = 60

text2 = 30

text3 = 50

text4 = 20

The number represents the chance that the text will appear.

Now, every time I run msgbox which would show one of the texts.

The result I want to get is that the msgbox will show the most "text1" Because the number of text1 is most high

and "text4" will appear fewest.

i hope that now you understand what I want..

if not then i am sorry for my English

Share this post


Link to post
Share on other sites
water

Can you calculate the probability in %?

Lets say

text1 = 50%

text2 = 15%

text3 = 25%

text4 = 10%

$iNumber = Random(0, 100)
Select
    Case $iNumber <= 50
        MsgBox(0, "", $sText1)
    Case $iNumber <= 65
        MsgBox(0, "", $sText2)
    Case $iNumber <= 90
        MsgBox(0, "", $sText3)
    Case Else
        MsgBox(0, "", $sText4)
EndSelect
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
TheSaint

I have the following table:

text1 = 60

text2 = 30

text3 = 50

text4 = 20

The number represents the chance that the text will appear.

Now, every time I run msgbox which would show one of the texts.

The result I want to get is that the msgbox will show the most "text1" Because the number of text1 is most high

and "text4" will appear fewest.

i hope that now you understand what I want..

if not then i am sorry for my English

Something like what water posted, because your four numbers need to total 100%, not 160% as you showed.

Think about it, if you want one item to appear 60% of the time, then the most any other item can appear, is 40%, not 50%, and then you want two other cases, for which you have nothing left. Lower them all so they add to 100.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
dragan

Something like what water posted, because your four numbers need to total 100%, not 160% as you showed.

Think about it, if you want one item to appear 60% of the time, then the most any other item can appear, is 40%, not 50%, and then you want two other cases, for which you have nothing left. Lower them all so they add to 100.

if 160 = 100%, then

60 = 37.50%

30 = 18.75%

50 = 31.25%

20 = 12.50%

to the number doesn't have to add to 100 always

 

$text1Chance = 60
$text2Chance = 30
$text3Chance = 50
$text4Chance = 20

$total = $text1Chance + $text2Chance + $text3Chance + $text4Chance
$totalRuns = 10

_Example1($totalRuns)

Func _Example1($times2run = 1)
    if $times2run < 1 Then Return

    $text1Chance100 = $text1Chance*100/$total
    $text2Chance100 = $text2Chance*100/$total + $text1Chance100
    $text3Chance100 = $text3Chance*100/$total + $text2Chance100
    $text4Chance100 = $text4Chance*100/$total + $text3Chance100

    For $i = 1 to $times2run
        $RandomNumber = Random(1, 100, 1)
        Select
            Case $RandomNumber <= $text1Chance100
                MsgBox(0, $i, $text1Chance & " - " & $text1Chance*100/$total & "%")
            Case $RandomNumber <= $text2Chance100
                MsgBox(0, $i, $text2Chance & " - " & $text2Chance*100/$total & "%")
            Case $RandomNumber <= $text3Chance100
                MsgBox(0, $i, $text3Chance & " - " & $text3Chance*100/$total & "%")
            Case Else
                MsgBox(0, $i, $text4Chance & " - " & $text4Chance*100/$total & "%")
        EndSelect
    Next
EndFunc

Share this post


Link to post
Share on other sites
TheSaint

@dragan - you are still adding to 100 with your percent, and he said chance, not times.

If he wanted Item 1 to appear 60 times for every 30 times for Item 2 and 50 times for Item 3 and 20 times for Item 4, then you would make the total percentage 160, then reduce to 100 and get the figures you gave.

Is that what he wants?

I'm not so sure?

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
gil900

 

if 160 = 100%, then

60 = 37.50%

30 = 18.75%

50 = 31.25%

20 = 12.50%

to the number doesn't have to add to 100 always

 

$text1Chance = 60
$text2Chance = 30
$text3Chance = 50
$text4Chance = 20

$total = $text1Chance + $text2Chance + $text3Chance + $text4Chance
$totalRuns = 10

_Example1($totalRuns)

Func _Example1($times2run = 1)
    if $times2run < 1 Then Return

    $text1Chance100 = $text1Chance*100/$total
    $text2Chance100 = $text2Chance*100/$total + $text1Chance100
    $text3Chance100 = $text3Chance*100/$total + $text2Chance100
    $text4Chance100 = $text4Chance*100/$total + $text3Chance100

    For $i = 1 to $times2run
        $RandomNumber = Random(1, 100, 1)
        Select
            Case $RandomNumber <= $text1Chance100
                MsgBox(0, $i, $text1Chance & " - " & $text1Chance*100/$total & "%")
            Case $RandomNumber <= $text2Chance100
                MsgBox(0, $i, $text2Chance & " - " & $text2Chance*100/$total & "%")
            Case $RandomNumber <= $text3Chance100
                MsgBox(0, $i, $text3Chance & " - " & $text3Chance*100/$total & "%")
            Case Else
                MsgBox(0, $i, $text4Chance & " - " & $text4Chance*100/$total & "%")
        EndSelect
    Next
EndFunc

thanks.

I changed it so it will work with Array.

#include <Array.au3>

Local $avArray[5]

$avArray[1] = "Case A|80"
$avArray[2] = "Case B|30"
$avArray[3] = "Case C|60"
$avArray[4] = "Case E|20"

_ArrayDisplay($avArray)
;Exit




;$text1Chance = 60
;$text2Chance = 30
;$text3Chance = 50
;$text4Chance = 20
 
;$total = $text1Chance + $text2Chance + $text3Chance + $text4Chance

$total = 0
For $a = 1 To UBound($avArray)-1
    $s_avArray = StringSplit($avArray[$a],"|",1)
    $total = $total+$s_avArray[2]
Next
;MsgBox(0,"",$total)




$totalRuns = 20
 
_Example1($totalRuns)
 
Func _Example1($times2run = 1)
    if $times2run < 1 Then Return
 
    ;$text1Chance100 = $text1Chance*100/$total
    ;$text2Chance100 = $text2Chance*100/$total + $text1Chance100
    ;$text3Chance100 = $text3Chance*100/$total + $text2Chance100
    ;$text4Chance100 = $text4Chance*100/$total + $text3Chance100
    For $i = 1 to $times2run
        
        $RandomNumber = Random(1, 100, 1)
        For $a = 1 To UBound($avArray)-1
            $Case = StringSplit($avArray[$a],"|",1)
        
            ;For $i = 1 to $times2run
            ;   $RandomNumber = Random(1, 100, 1)
            ;   If $RandomNumber <= $text1Chance100 Then
            ;           MsgBox(0, $i, $text1Chance & " - " & $text1Chance*100/$total & "%")
            ;   ElseIf $RandomNumber <= $text2Chance100 Then
            ;           MsgBox(0, $i, $text2Chance & " - " & $text2Chance*100/$total & "%")
            ;   ElseIf $RandomNumber <= $text3Chance100 Then
            ;           MsgBox(0, $i, $text3Chance & " - " & $text3Chance*100/$total & "%")
            ;   Else
            ;           MsgBox(0, $i, $text4Chance & " - " & $text4Chance*100/$total & "%")
            ;   EndIf
            ;Next
            If $RandomNumber <= $Case[2] Then
                MsgBox(0,$i,$Case[1] & " - " & $Case[2]*100/$total & "%")
            EndIf
        Next
    Next
EndFunc

I think it's fine ..

But take a look to make sure there is no bug.

Share this post


Link to post
Share on other sites
gil900

@dragan - you are still adding to 100 with your percent, and he said chance, not times.

yes, i said chance.

i need that it will work by the chance

Edited by gil900

Share this post


Link to post
Share on other sites
gil900

i am sorry but can someone help me to write the following function:

the function get input in this format:

text.##,text.##,text.##

*Instead of "##" should be a number between 1 to 100 that represents the chance

*Instead of "text" should be a text that represents the result and the function should return one of the text's

input for example:

case1.20,case2.80,case3.50

at this example, i call to the function with this input.

What is supposed to happen is that the function mostly return the text "case2" in the input.

( "case1" - 20% chance to be happen , "case2" - 80% chance to be happen , "case3" - 50% chance to be happen)

What I did before in post 9 it is not good.. I can not be based on it.

I hope you help me.

I will also donate for you something in Example Scripts
.

Thanks :)

EDIT:

the function  can get the input as array. it is also good.

Edited by gil900

Share this post


Link to post
Share on other sites
gil900

after this number of attempts:

28mfp1c.jpg

this is what i have so far:

#include <Array.au3>

$Input = "case1.10,case2.80,case3.85"

$s_Input = StringSplit($Input,",",1)


Local $aNumbers[1]
For $a = 1 To $s_Input[0]
    $s2_Input = StringSplit($s_Input[$a],".",1)
    _ArrayAdd($aNumbers,$s2_Input[2])
Next
;_ArrayDisplay($s_Input)
;Exit
While 1
    $Number = Random(1,100,1)
    For $a = 1 To $s_Input[0]
        ;MsgBox(0,"",$s_Input[$a]&" - "&$aNumbers[$a])
        If $Number > 100-$aNumbers[$a] Then
            ConsoleWrite($s_Input[$a]&@CRLF)
        EndIf
    Next
    ConsoleWrite("--------------------"&@CRLF)
    Sleep(1500)
WEnd
Edited by gil900

Share this post


Link to post
Share on other sites
kylomas

gil9000,

Is this what you are looking for...?

#include <Array.au3>

$Input = "case1.10,case2.80,case3.85,case5.14,case2.199"

ConsoleWrite(_highest_certainty($Input) & @LF)

func _highest_certainty($str)

    ; validate input - create 2D array for sort

    local $aTmp10 = stringsplit($str,','), $aTmp20[$aTmp10[0]+1][2], $aTmp30[2]
    for $1 = 1 to $aTmp10[0]
        if not stringregexp($aTmp10[$1],'\w+\d+\.\d+$') then return seterror(1)
        $aTmp30 = stringsplit($aTmp10[$1],'.',2)
        $aTmp20[$1][0] = $aTmp30[0]
        $aTmp20[$1][1] = int($aTmp30[1])
    next

    _arraysort($aTmp20,1,-1,-1,1)

    return $aTmp20[0][0] & '.' & $aTmp20[0][1]

endfunc

kylomas

edit: corrected regex  pattern

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
gil900

gil9000,

Is this what you are looking for...?

#include <Array.au3>

$Input = "case1.10,case2.80,case3.85,case5.14,case2.199"

ConsoleWrite(_highest_certainty($Input) & @LF)

func _highest_certainty($str)

    ; validate input - create 2D array for sort

    local $aTmp10 = stringsplit($str,','), $aTmp20[$aTmp10[0]+1][2], $aTmp30[2]
    for $1 = 1 to $aTmp10[0]
        if not stringregexp($aTmp10[$1],'\w+\d+\.\d+') then return seterror(1)
        $aTmp30 = stringsplit($aTmp10[$1],'.',2)
        $aTmp20[$1][0] = $aTmp30[0]
        $aTmp20[$1][1] = int($aTmp30[1])
    next

    _arraysort($aTmp20,1,-1,-1,1)

    return $aTmp20[0][0] & '.' & $aTmp20[0][1]

endfunc

kylomas

thanks!

i will try it.

this is what i did so far...  I think it my test code start to works better

#include <Array.au3>

$Input = "case1.20,case2.90,case3.50"

$s_Input = StringSplit($Input,",",1)


Local $aNumbers[1]
$total = 0
For $a = 1 To $s_Input[0]
    $s2_Input = StringSplit($s_Input[$a],".",1)
    $total = $total+$s2_Input[2]
    _ArrayAdd($aNumbers,$s2_Input[2])
Next
;_ArrayDisplay($s_Input)
;Exit
While 1
    $Number = Random(1,100,1)
    Local $aResult[1] , $get = 0
    For $a = 1 To $s_Input[0]
        ;MsgBox(0,"",$s_Input[$a]&" - "&$aNumbers[$a])
        If $Number > 100-$aNumbers[$a] Then
            
            ;ConsoleWrite($s_Input[$a]&@CRLF)
            $get = 1
            _ArrayAdd($aResult,$aNumbers[$a])
        EndIf
        If $a = $s_Input[0] Then
            If $get = 1 Then
                $min = _ArrayMin($aResult,0,1)
                ;_ArrayDisplay($aResult)
                ;MsgBox(0,"",$min)
                For $a2 = 1 To $s_Input[0]
                    $var = StringSplit($s_Input[$a2],".",1)
                    If $var[2]*1 = $min Then
                        $Outptut = $var[1]
                        $get = 0
                        ExitLoop
                    EndIf
                Next
            Else
                $Outptut = "X"
            EndIf
        EndIf    
    Next
    ConsoleWrite($Outptut&@CRLF)
    Sleep(1500)
WEnd

EDIT:

this is not what i need.

i try my last code and then you will understand what I want

EDIT2:

Sometimes my code returns an "X". This should not happen so don't try to do the same thing.

Edited by gil900

Share this post


Link to post
Share on other sites
kylomas

this is not what i need

 

I guess that is for me...

Good Luck,

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
gil900

I guess that is for me...

Good Luck,

kylomas

This too difficult? Or you did not understand what I need?

It's all about probability .. And that's what very difficult for me.

What I want to do is control the level of probability of each case.

The following example:

case1.20, case2.80, case3.50

shows the cases and each case have a level of probability.

the probability that case1 will heppen is 20

the probability that case2 will heppen is 80

the probability that case3 will heppen is 50

What is supposed to happen that at the most of the times case2 will happen because case2 have the highest probability level. but case2 will NOT heppen always because sometimes "the luck plays" and case1 or case3 will happen. at this situation(when case3 not happen) most likely that case2 will happen because his level of the probability  is 50 and it is higher then the probability level of case1 (20) . but again - case2 also will NOT heppen always and case1 or case3 will happen Instead of case2.

this is my best explanation. i hope that now you got that.

I have given up. :(

if someone want to try to do it as a challenge so i will grateful

Edited by gil900

Share this post


Link to post
Share on other sites
gil900

Share this post


Link to post
Share on other sites
terrypin

I have the following table:

 

text1 = 60

text2 = 30

text3 = 50

text4 = 20

 

The number represents the chance that the text will appear.

 

I'm an AutoIt novice so can't contribute at all on the coding. But the key point that gil900 missed out of the question (leading to such a long thread!) was that the items or conditions listed are plainly not mutually exclusive.

 

Presumably the language problem made a solid example difficult to describe. Off the top of my head:

 

The first 160 customers entering a large store were:

 

Male = 60

Over 50 years old = 30

Carrying an umbrella = 50

Scottish = 20

 

That provides a rough estimate of the respective probabilities of those (largely) independent characterstics, which clearly don't have to add up to 1, or 100%. Repeated MsgBox displays could then simulate that distribution.

 

--

Terry, East Grinstead, UK

Edited by Melba23
Fixed tags

Share this post


Link to post
Share on other sites
water

If you are correct with your assumption then the OP needs to much better describe his problem or the goal he tries to achieve.

If the OP uses Google Translate we could get a better view.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
gil900

yes, i used google translate.

i just wanted to know - is my explanation in post #16 is good enough?

in  September 2009 Shafayat did a very great job and I'm really grateful for his job..

he really saved me!!

many thanks to Shafayat! :thumbsup:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×