Selecting a random name from a list
Moderators: Dorian (MJT support), JRL
Selecting a random name from a list
Hi,
I want to write a macro which I give him a list of names and it selects a name from the list randomaly, and then it writes the name with the command "send".
How do I write a macro which selects a random name from a defined list?
thanks.
I want to write a macro which I give him a list of names and it selects a name from the list randomaly, and then it writes the name with the command "send".
How do I write a macro which selects a random name from a defined list?
thanks.
Here's a simple example:
Let>Names[1]=Fred
Let>Names[2]=Sally
Let>Names[3]=Harry
Let>Names[4]=John
Let>Names_Count=4
Random>4,rndnum
Let>rndnum=rndnum+1
Let>outname=Names[%rndnum%]
Send>outname
Let>Names[1]=Fred
Let>Names[2]=Sally
Let>Names[3]=Harry
Let>Names[4]=John
Let>Names_Count=4
Random>4,rndnum
Let>rndnum=rndnum+1
Let>outname=Names[%rndnum%]
Send>outname
MJT Net Support
[email protected]
[email protected]
exactly what I looked for
It works!
thank you very much
thank you very much
- machinogodzilla
- Newbie
- Posts: 17
- Joined: Sun Jul 30, 2006 11:32 pm
Hi!
I would like to complicate this problem a little bit. What to do if you want to eliminate the name which has been choicen randomly from the list of the names that it will not apper in the next draw? And this way until all the names will have been used. E.g. we have got four names in above example thus after the first draw there will be only three names remaining. After the second one two and so on.
Thanks!
I would like to complicate this problem a little bit. What to do if you want to eliminate the name which has been choicen randomly from the list of the names that it will not apper in the next draw? And this way until all the names will have been used. E.g. we have got four names in above example thus after the first draw there will be only three names remaining. After the second one two and so on.
Thanks!
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
Someone will probably come along with a 3 line solution, but here's one quick way to do it. Note that this is very simple randomization suitable for deciding who takes out the garbage, but not for a serious application.
//fill the Names array
Let>Names[1]=Fred
Let>Names[2]=Sally
Let>Names[3]=Harry
Let>Names[4]=John
//create the num array size = max and fill with numbers from 1 to max
Let>max=4
Let>n=1
label>start
Let>num[%n%]=%n%
Let>n=n+1
If>n>max,done,start
label>done
//shuffle the numbers by stepping through the array and swapping the
//number in each position with the number from a randomly selected
//position. You can do this step as many times as you like.
Let>randmax=max-1
Let>q=1
Label>shuffle
random>randmax,p
Let>p=p+1
Let>temp=num[%q%]
Let>num[%q%]=num[%p%]
Let>num[%p%]=temp
Let>q=q+1
If>q>max,done2,shuffle
Label>done2
//use the shuffled numbers in the num array to pull names from the Names array
Let>k=0
Repeat>k
Let>k=k+1
Let>r=num[%k%]
MessageModal>Names[%r%]
Until>k,max
Label>finish
//fill the Names array
Let>Names[1]=Fred
Let>Names[2]=Sally
Let>Names[3]=Harry
Let>Names[4]=John
//create the num array size = max and fill with numbers from 1 to max
Let>max=4
Let>n=1
label>start
Let>num[%n%]=%n%
Let>n=n+1
If>n>max,done,start
label>done
//shuffle the numbers by stepping through the array and swapping the
//number in each position with the number from a randomly selected
//position. You can do this step as many times as you like.
Let>randmax=max-1
Let>q=1
Label>shuffle
random>randmax,p
Let>p=p+1
Let>temp=num[%q%]
Let>num[%q%]=num[%p%]
Let>num[%p%]=temp
Let>q=q+1
If>q>max,done2,shuffle
Label>done2
//use the shuffled numbers in the num array to pull names from the Names array
Let>k=0
Repeat>k
Let>k=k+1
Let>r=num[%k%]
MessageModal>Names[%r%]
Until>k,max
Label>finish
- machinogodzilla
- Newbie
- Posts: 17
- Joined: Sun Jul 30, 2006 11:32 pm
- machinogodzilla
- Newbie
- Posts: 17
- Joined: Sun Jul 30, 2006 11:32 pm
Let me put it this way. Instead of Sally or Harry from the above example I would like to have cursor's positions on the screen (x,y) preset by me and put to an array (if possible). From these places I would like the macro to choice one of them randomly, make a click, then eliminate, choice another place, click, eliminate and so on until there are no places left in the array.
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
I think the simplest way would be to use an array, e.g. cursorpos[], and store the coordinates with a delimiter eg for x=100, y = 300 Let>cursorpos[1]=100|300
Then you would use Separate> to split the coordinates back out into x and y
Separate>cursorpos[1],|,gopos
then gopos_1 would be the first coord and gopos_2 would be the second so you could use those coords with MouseMove>
MouseMove>%gopos_1%,%gopos_2%
Then you would use Separate> to split the coordinates back out into x and y
Separate>cursorpos[1],|,gopos
then gopos_1 would be the first coord and gopos_2 would be the second so you could use those coords with MouseMove>
MouseMove>%gopos_1%,%gopos_2%
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Or use two arrays:
Let>cursorpos_x[1]=100
Let>cursorpos_y[1]=300
Let>cursorpos_x[1]=100
Let>cursorpos_y[1]=300
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- machinogodzilla
- Newbie
- Posts: 17
- Joined: Sun Jul 30, 2006 11:32 pm
Thank you very much! That is exactly what I was hoping to exist in msched
I was trying to use two arrays before but because of the randomisation I could not make it. I was receiving each array shuffled different way. And I needed matching pairs. But with the 'separate' command and the rest that became a piece of cake Thx!
I was trying to use two arrays before but because of the randomisation I could not make it. I was receiving each array shuffled different way. And I needed matching pairs. But with the 'separate' command and the rest that became a piece of cake Thx!
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
You can shuffle two arrays in sync, but it's slower (not an issue with these tiny arrays) and I still think the other way is simpler.
Let>randmax=max-1
Let>q=1
Label>shuffle
random>randmax,p
Let>p=p+1
Let>tempx=xpos[%q%]
Let>tempy=ypos[%q%]
Let>xpos[%q%]=xpos[%p%]
Let>ypos[%q%]=ypos[%p%]
Let>xpos[%p%]=tempx
Let>ypos[%p%]=tempy
Let>q=q+1
If>q>max,done2,shuffle
Label>done2
Let>randmax=max-1
Let>q=1
Label>shuffle
random>randmax,p
Let>p=p+1
Let>tempx=xpos[%q%]
Let>tempy=ypos[%q%]
Let>xpos[%q%]=xpos[%p%]
Let>ypos[%q%]=ypos[%p%]
Let>xpos[%p%]=tempx
Let>ypos[%p%]=tempy
Let>q=q+1
If>q>max,done2,shuffle
Label>done2