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.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
komadayim
Posts: 5
Joined: Tue Dec 10, 2013 7:31 pm

How to select randomly from few numbers?

Post by komadayim » Sat Jun 10, 2017 11: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!
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to select randomly from few numbers?

Post by chivracq » Sat Jun 10, 2017 12:08 pm

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)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
komadayim
Posts: 5
Joined: Tue Dec 10, 2013 7:31 pm

Re: How to select randomly from few numbers?

Post by komadayim » Sat Jun 10, 2017 12:41 pm

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:
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to select randomly from few numbers?

Post by chivracq » Sat Jun 10, 2017 1:40 pm

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)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
komadayim
Posts: 5
Joined: Tue Dec 10, 2013 7:31 pm

Re: How to select randomly from few numbers?

Post by komadayim » Sat Jun 10, 2017 7: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!
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to select randomly from few numbers?

Post by chivracq » Sat Jun 10, 2017 7: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)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Post Reply