Set random negative number with Random Functions in Jmeter? - jmeter

How can i set random negative number in Message content in AMQP publisher via JMETER?
I try this:
"customerId": ${__Random(-1, -100 )}
but response message is: time out.
If I set:
"customerId": ${__Random(1, 100 )}
response is work.
How can i set negative range in this field?

Well you're telling it to find a number bigger than -1 and smaller than -100, of which no numbers exist.
${__Random(min, max)} this is really what is happening so the smaller number goes first then the larger number.
try "customerId": ${__Random(-100, -1 )}

Related

How to extract the maximum value key from an array?

[1]: https://i.stack.imgur.com/szHJJ.png [2]: https://i.stack.imgur.com/8Oic4.png
There is an array, you need to pull the maximum value and its key from it. Each number from the array has its own key, and I need to pull exactly the one that is associated with the maximum number. With the help of regularity, I pulled out the numbers and through jsr 223, the sampler found the maximum number. Now the question is: how to extract the key of exactly the maximum number? Don't kick, a week since I started studying jmeter after lr, so I'm suffering. And the text was translated into English through a translator.
The key itself from part of the array (what needs to be pulled): dUUyTlFoUmhQMmExbCtFZ2VCY09uQT09LS1FK3lZbzJlakFUeEJoNlhCV3poRzV3PT0=--4814f46102fd5ecaf9f440be0a8925644927b3d0 described above the way to find the maximum number, in my case
the number 69, now i need to somehow find the key to the maximum number and then apply it in the request.
Part of the array:
dUUyTlFoUmhQMmExbCtFZ2VCY09uQT09LS1FK3lZbzJlakFUeEJoNlhCV3poRzV3PT0=--4814f46102fd5ecaf9f440be0a8925644927b3d0" /><label class="collection_radio_buttons" for="challenger_order_selected_duuytlfoumhqmmexbctfz2vcy09uqt09ls1fk3lzbzjlakfueejonlhcv3porzv3pt0--4814f46102fd5ecaf9f440be0a8925644927b3d0">69</label></span></div>```
You already have the value and even highlighted it in blue, just iterate through existing JMeter Variables values, get the match number and get the key which corresponds to the match number.
Example code:
for (int i = 1; i < (vars.get('maxValue_matchNr') as int); i++) {
if (vars.get('maxValue_' + i + '_g2').equals(vars.get('maxValue_max'))) {
vars.put('maxKey_max', vars.get('maxValue_' + i + '_g1'))
break;
}
}
You should be able to refer the extracted value as ${maxKey_max} where required.
Also using "regularity" for getting the values from HTML might not be the best idea, maybe it worth considering using CSS Selector Extractor instead?

Positive random number generation with given mean and standard deviation

I am working on a simulation project. Need help on random number generation. I need two sets of random numbers.
Properties:
Primary set (var_a) > Normally distributed, greater than 0, with given mean and std.
Secondary set (var_b) -> Same as a primary set, with an addition, that second set cannot be greater than primary set. The reason being the output of a deterministic function will be in percentage between 0-1 only. For example:
service level calculation
import numpy as np
n = 100000
# Calls Handled
callshandled = np.random.normal(loc=65, scale=97, size=n)
print('Calls handled: ', callshandled)
# Call handled within sl. Has to always be less or equal to Calls Handled
ansinsl = np.random.normal(loc=60, scale=82, size=n)
print('Answered in SL', ansinsl)
# Service Level - Has to be between 0-1. With normal distribution we get values in negative
sl = np.array(ansinsl)/np.array(callshandled)
print('Service level', sl)
Calls handled: [ 43.26825426 129.79198758 31.56460354 ... 37.45059791 1.71420416
-94.87241356]
Answered in SL [-12.72293091 204.28084996 232.25722235 ... 166.03208722 -53.69933624
-36.71949656]
Service level [ -0.29404771 1.57390956 7.35815427 ... 4.43336279 -31.32610312
0.38704082]
There is a well-known “natural” way of generating pairs of Gaussian pseudo-random variates, known as Box-Muller.
You could try it that way:
generate pairs of unit normal variates à la Box-Muller
scale the pairs to whatever your (µ,σ) parameters are
reject the pairs that do not fit your criteria

Generate increasing random number rails

I've a random number generator code:
5.times.map { [*0..9].sample }.join.to_i
It gives me random numbers like 63832, 42337, 34998. As you can see that they are completely random, but how to make than I would get only in an increasing way? Not 63832, 42337, 34998, but 34998, 42337, 63832 (this is just an example, Ideally I would get smth like 00[number] => 0025, where 25 is a random number which was generated.
Hope my explanation is understandable :)
If you have the current / last random number, you can generate a larger one by simply adding a random number to it, e.g:
def generate(base = 0)
base + rand(1_000..10_000)
end
number = generate #=> 9635
number = generate(number) #=> 17761
number = generate(number) #=> 22082
number = generate(number) #=> 31061
Each number is 1,000 to 10,000 larger than its predecessor.
An alternative approach, if you want to generate all random numbers within a known range:
[*1..10000].sample(5).sort
# => [602, 5608, 7912, 8384, 8714]
However, this only works if you want to fetch all random numbers upfront, rather than continuously being able to generate new ones which are larger.
It's also not a good approach if your upper limit is very big - e.g. this will freeze your system and need to be cancelled:
[*1..10000000000].sample(5).sort
...But in that case, since the numbers are so huge, you can surely get away with the tiny risk of having a collision:
5.times.map{ rand(1..10000000000) }.sort
# => [460188573, 555213355, 3576967759, 3994239233, 9570165205]

Cheapest permutation calculation

I have a collection of documents. The relevant structure of the object for this question would be:
{
"_id":ObjectId("5099803df3f4948bd2f98391"),
...
"type": "a",
"components":{
"component2": 20,
"component3": 10,
},
"price": 123
...
}
I'm currently using an old set of code that I wrote a while ago to find the cheapest permutation of a combination needed. I'm not sure if this is possible to do with just a query, but thought I would ask before moving any further.
Specifics: There are 10 possible "type"'s ( a-j ). There are 4 possible "component"'s types. Items will have at least 1 "component", but can have up to 2. They will never have more than 2. While the types are limited to 2, the value ( "grade" ) of the components can range. So either exactly 1 or exactly 2 components, with any possible combination of component values/grades.
There are 10k records, and what I'm needing to do is find the the lowest possible price, having at least one of each type, that yields me at least my desired grade for either the one or two components I enter.
The expected result would always have one of each type ( 10 total ).
In layman's I'd be asking the data set for the cheapest combination of component2's that exceed 200. Or, the cheapest combination of component1/component3 that exceed a 150 component1 grade and exceed a 150 component3 grade.
Again though that combination is restricted because it must have exactly/only one of each type. So a better price could certainly be achieved if there was 10 type "a"'s, but it would need to be 1 "a", 1 "b", etc.
I don't think it is, but is it possible this could somehow be achieved with a query alone?

find endpoints for range given a value within the range

I am trying to solve a simple problem, but at the moment I cannot think of a better solution. I am testing an API that is not documented.
There is an ID used to fetch objects and it has a min and max value with random values missing in-between. I'm trying to test the responses I receive for random objects, but to find objects, I need to have valid IDs.
It would be very inefficient to test random numbers and hope that I get an object back. The best I can do is find a range, get a random number between that range and check if it exists before conducting tests.
A sample list of all of the IDs in the database might look like this:
[1005, 25984, 25986, 29587, 30000, ...]
Assuming the deviation from one value to another will never exceed C, e.g. from the first value to the next value, the difference will never be greater than a pre-defined constant, how would you calculate the min/max of the range given only one value in the range?
Starting from a given value and looping until the last value is found is horrible but that is how it was implemented by previous devs. Below is pseudocode that more or less covers what they do.
// this can be any valid object ID from the database
// assuming the ID's in the database are [1005, 25984, 25986, 29587, 30000]
// "i" could be any one of these values
var i = givenPredefinedObjectId;
var deviation = 100;
// objectWithIdExists() is going to lookup an object with the ID "i" in the database
// if there is no object with the ID "i" , it will return false
// otherwise the object will get tested and return true
while(objectWithIdExists(i)){
i++;
}
for(i; i < i+deviation; i++){
if(objectWithIdExists(i)){
goto while loop;
}
}
endPoint = i - deviation;
Assuming there is no knowledge about the possible values except you can check if they exist and you are given one valid value (there is no array with all possible IDs, that was just an example), how would you find the min/max values?
Unbounded binary search is feasible, with a factor of C slowdown. Given an algorithm for unbounded binary search that, given access to the oracle less_equal(n) for some natural number n, returns n in time O(log n), implement the oracle on input k by querying all of the IDs C*k, C*k+1, ..., C*k+C-1 and reporting that k is less than or equal to n if and only if one ID is found. The running time is O(C*log((max-min)/C)).

Resources