Jump to content
Sign in to follow this  
Vladi243

Generate Random word

Recommended Posts

Vladi243

I found this topic by search.

There is this script

$string="a,b,c,d"
$Array=StringSplit($string,",")
$i=Random(0,UBound($Array)-1,1)
MsgBox(0,"Random",$Array[$i])

It's generates a random letter (a/b/c/d). The problem is that sometimes it generates the number "4". Why?

Can you give me better script for generating random word?

Share this post


Link to post
Share on other sites
monoceres

I found this topic by search.

There is this script

$string="a,b,c,d"
 $Array=StringSplit($string,",")
 $i=Random(0,UBound($Array)-1,1)
 MsgBox(0,"Random",$Array[$i])

It's generates a random letter (a/b/c/d). The problem is that sometimes it generates the number "4". Why?

Can you give me better script for generating random word?

Because the person who wrote forgot that the first element in the array returned by StringSplit is in fact the count of elements in the array.

Just change Random(0...... to Random(1....

:)


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
Vladi243

ohhh... thanks. now it's working good.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.