Jump to content
Sign in to follow this  

Array: Randomly select delimeters but only once

Recommended Posts

I have a string that returns an array. The number of delimeters vary from 3 to 6 and the first 2 delimeters are not important for the function and are excluded.

I have a For-Next loop, and how many times it will loop depends on how many delimeters are in the array, subtracted by 2 because as I said the first 2 are not important here.

Currently inside the loop I have it select the delimeters in order starting with the 3rd. I don't want to do this though. I need the script to select one of the delimeters, not in any order. I thought of using the random function but the problem with random is sometimes it picks the same number as before. Since this loop ONLY loops as many times as there are delimeters-2, this is unacceptable. I need within each loop to pick a delimeter, but as I said not in any order and it cannot select one twice.

An example of a string that's being split into an array might be 0,0,1,2,3. In this example it will loop 3 times, selecting either 1,2 or 3. I don't want it in any order.




3,1,2 etc.

For $count=1 to $con[0]-2; loops as many times as there are delimeters-2

$num = $con[$count+2]; selects the next delimeter(this one in order)

The loop is definitely what's throwing me off, any suggestions would be greatly appreciated. :ph34r:

Share this post

Link to post
Share on other sites

Maybe this will get you started.

while StringLen ($old)<$delim[0]
$y=int(Random ( 1,$delim[0]+1 ) )
if stringinstr($old,$y)>0 then
msgbox(1,$delim[$y],"Random this time was:" & $y)
$old=$old & $y
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...