Sign in to follow this  
Followers 0
tierbone

Weighted Random

2 posts in this topic

I am currently just using something similar to the following to select a string from an array, and it works fine.

Func Randomarray()
    $array[1] = "hi"
    $array[2] = "hey"
    $array[3] = "hello"
    $array[4] = "yo"
    $array[5] = "hey1"
    $array[6] = "hi1"
    $array[7] = heyhey"
    $randstring = Random(1, ubound($array),1)
    Return $array[$randemail]
EndFunc

What I am trying to do is have it select 1 or more strings at a more/less frequent interval that the others. Is there already a funcion that I can use, if not, where would I start in making it?

Share this post


Link to post
Share on other sites



I am currently just using something similar to the following to select a string from an array, and it works fine.

Func Randomarray()
     $array[1] = "hi"
     $array[2] = "hey"
     $array[3] = "hello"
     $array[4] = "yo"
     $array[5] = "hey1"
     $array[6] = "hi1"
     $array[7] = heyhey"
     $randstring = Random(1, ubound($array),1)
     Return $array[$randemail]
 EndFunc

What I am trying to do is have it select 1 or more strings at a more/less frequent interval that the others. Is there already a funcion that I can use, if not, where would I start in making it?

If you have a list of numbered N items and you want some items to be chosen more frequently then in principal you could increase the size of the list and duplicate the items you want to be picked more frequently. Or you could get a random number between a larger range than th enumber of items and then have some way of deciding what the answer meant.

Eg

Func Randomarray()
     $array[1] = "hi"
     $array[2] = "hey"
     $array[3] = "hello"
     $array[4] = "yo"
     $array[5] = "hey1"
     $array[6] = "hi1"
     $array[7] = heyhey"
     $randstringA = Random(1, 10*ubound($array),1)
switch $randomstringA
  case 1 to 3
      $Randomstring = 1
  Case 4 to 10
   $$randomstring = 2
  ;etc, weighting as required

  endswitch
     Return $array[$randemail]
 EndFunc

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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  
Followers 0