How to select randomly from few numbers?

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

How to select randomly from few numbers?

by komadayim on Sat Jun 10, 2017 4:15 am

Hello there,

I'm trying to fill a form and for the each line I want to fill the form with specific numbers I've wrote earlier.

I've tried to to it with min-max random numbers but it won't work since I want to select between 4,9,12 but with the min-max random code it gives me 4-5-6-7-8-9-10-11-12 numbers as output.

My random code is:

VERSION BUILD=9030808 RECORDER=FX
TAB T=1
SET !VAR1 EVAL("var min = 1; var max = 5; var randomNumber = Math.floor(Math.random() * (max - min + 1)) + min; randomNumber;")
TAG POS={{!VAR1}} TYPE=LABEL ATTR=CLASS:freebirdFormviewerViewItemsGridCell&&TXT:

I need something like this

VERSION BUILD=9030808 RECORDER=FX
TAB T=1
SET !VAR1 EVAL("var 4; 9; 12; var randomNumber = Math.floor(Math.random() * (max - min + 1)) + min; randomNumber;")
TAG POS={{!VAR1}} TYPE=LABEL ATTR=CLASS:freebirdFormviewerViewItemsGridCell&&TXT:

Bottom line is; how can I select randomly between pre defined numbers?

Thanks!
komadayim
 
Posts: 5
Joined: Tue Dec 10, 2013 12:31 pm

Re: How to select randomly from few numbers?

by chivracq on Sat Jun 10, 2017 5:08 am

komadayim wrote:Hello there,

I'm trying to fill a form and for the each line I want to fill the form with specific numbers I've wrote earlier.

I've tried to to it with min-max random numbers but it won't work since I want to select between 4,9,12 but with the min-max random code it gives me 4-5-6-7-8-9-10-11-12 numbers as output.

My random code is:

Code: Select all
VERSION BUILD=9030808 RECORDER=FX
TAB T=1
SET !VAR1 EVAL("var min = 1; var max = 5; var randomNumber = Math.floor(Math.random() * (max - min + 1)) + min; randomNumber;")
TAG POS={{!VAR1}} TYPE=LABEL ATTR=CLASS:freebirdFormviewerViewItemsGridCell&&TXT:


I need something like this

Code: Select all
VERSION BUILD=9030808 RECORDER=FX
TAB T=1
SET !VAR1 EVAL("var [b]4; 9; 12;[/b] var randomNumber = Math.floor(Math.random() * (max - min + 1)) + min; randomNumber;")
TAG POS={{!VAR1}} TYPE=LABEL ATTR=CLASS:freebirdFormviewerViewItemsGridCell&&TXT:


Bottom line is; how can I select randomly between pre defined numbers?

Thanks!

FCIM...! :mrgreen:
=> iMacros for FF v9.0.3, FF53...?, OS...?

Assign your 3 Numbers to an Array and apply your Random Nb to the Index within the Array with [min,max]=[0,2]. (Is just one Solution...)
An easy way to get your Nb's in a Array is to define them all together in one String "4;9;12" and use 'split()' on the Separator in the String...

>>>

And hum, you never finished your previous Thread from 3.5 years ago a bit "neatly"... :roll:
You are expected to share your Solution / Final Script to finish a Thread a bit correctly and useful for other Users... (even if hum..., I'm not sure that Thread would help many People searching the Forum because of its useless (= non-Descriptive) Thread Title ("A complicated problem")...)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6471
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: How to select randomly from few numbers?

by komadayim on Sat Jun 10, 2017 5:41 am

Hello chivracq,

Thank you for your reply. I'm not FF 53.0.3 with the latest version of iMacros and windows 10. Sorry for not mentioning them.

I've tried to google your solutions but couldn't find anything.

Is there an example I can take a look at? I couldn't find arraying and using indexs for imacros. I guess i should use scripts but I have no idea about them. :|

--

Sorry about the earlier post, I couldn't find a solution to that problem as far as I can remember and end up doing it manually. :oops:
komadayim
 
Posts: 5
Joined: Tue Dec 10, 2013 12:31 pm

Re: How to select randomly from few numbers?

by chivracq on Sat Jun 10, 2017 6:40 am

komadayim wrote:Hello chivracq,

Thank you for your reply. I'm
Code: Select all
not FF 53.0.3 with the latest version of iMacros and windows 10.
Sorry for not mentioning them.

I've tried to google your solutions but couldn't find anything.

Is there an example I can take a look at? I couldn't find arraying and using indexs for imacros. I guess i should use scripts but I have no idea about them. :|

--

Sorry about the earlier post, I couldn't find a solution to that problem as far as I can remember and end up doing it manually. :oops:

OK for FCI, even if still a bit unclear because of the "not", but never mind, it shouldn't play a role in this Case...

Well, you don't need to "search" anything, simply check how the JavaScript 'split()' Command works...

Code: Select all
SET Numbers "4;9;12"
SET !VAR1 EVAL("var min=0, max=2; var nb='{{Numbers}}'; var a=nb.split(';'); var rd=Math.floor(Math.random()*(max-min+1))+min; a[rd];")
PROMPT Numbers:<SP>_{{Numbers}}_<BR>VAR1:<SP>_{{!VAR1}}_
(Tested on iMacros for FF v8.8.2, Pale Moon v26.3.3 (=FF47), Win10-x64.)

Or, if you prefer, maybe easier to follow/understand as it reuses directly your original Code..., and to debug, ah-ah...!:
Code: Select all
SET Numbers "4;9;12"
SET Random_Index EVAL("var min=0, max=2; var randomNumber=Math.floor(Math.random()*(max-min+1))+min; randomNumber;")
SET !VAR1 EVAL("var nb='{{Numbers}}'; var ri='{{Random_Index}}'; var a=nb.split(';'); a[ri];")
PROMPT Numbers:<SP>_{{Numbers}}_<BR><BR>Random_Index:<SP>_{{Random_Index}}_<BR>VAR1:<SP>_{{!VAR1}}_
(Yep, works as well...!)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6471
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: How to select randomly from few numbers?

by komadayim on Sat Jun 10, 2017 12:18 pm

Dear chivracq,

Thank you for your reply, this one worked nicely! :) It's hard to find information when you don't know enough about something. :mrgreen:

Sorry for my confusing reply earlier, I was a bit tired and couldn't get my words together.

Best wishes!
komadayim
 
Posts: 5
Joined: Tue Dec 10, 2013 12:31 pm

Re: How to select randomly from few numbers?

by chivracq on Sat Jun 10, 2017 12:51 pm

komadayim wrote:Dear chivracq,

Thank you for your reply, this one worked nicely! :) It's hard to find information when you don't know enough about something. :mrgreen:

Sorry for my confusing reply earlier, I was a bit tired and couldn't get my words together.

Best wishes!

Well, I tested both (Scripts) and they both work..., the 2nd one is maybe easier to understand as it goes a bit more Step by Step, and reuses what you were already trying to use... You were very close and only missing one Step...

I normally don't/rarely write Scripts for Users, I prefer to let you understand what "you are doing" and let you find the Solution by yourself, which is more rewarding for yourself anyway than having sbd writing your Script..., so I hope you now understand a bit how "my" Solution works...
I hardly know anything about JavaScript myself, that's why I do all my Scripts in pure '.iim' and only use a few "simple" JS Commands like 'split()' in 'EVAL()' Statements...

Glad I could help and good luck for the "rest"... :D
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6471
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to General Support & Discussions

Who is online

Users browsing this forum: Majestic-12 [Bot] and 6 guests

-->