I'm generating coupons with the following charset:
1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ (36 Characters)
Using this pattern: (replace hash tag with a character)
####-####-####-#### (16 chars)
36^16 = 7,958,661,109,946,400,884,391,936
How do you figure out the probability of guessing a code if I generated 1000 codes randomly?
Basically since you're generating each new code randomly (so there could be dups), each generation has a:
1/36^16 probability of being correct
...so the chance that none of the codes are correct are:
[(36^16-1)/36^16)]^1000
...and so the probability of guessing the code is 1 minus this:
1 - [(36^16-1)/36^16)]^1000
Related
I have one column (im = 160648) and row (jm = 1). I want to transform that to a matrix with sizes (im = 344) and (jm=467)
my program code is
program matrix
parameter (im=160648, jm=1)
dimension h(im,jm)
integer::h
open (1,file="Hasil.txt", status='old')
open (2,file="HasilNN.txt", status='unknown')
do i=1,jm
read(1,*)(h(i,j)),j=1,jm)
end do
do i=1,im
write(2,33)(h(i,j),j=1,jm)
end do
33 format(1x, 344f10.6)
end program matrix
the error code that appears when read(1,*)(h(i,j)),j=1,jm)
the data type is floating data.
Your read loop is:
do i=1,jm
read(1,*)(h(i,j)),j=1,jm)
end do
Shouldn't do i=1,jm be do i=1,im ?
This would imply there are "im" records (lines) in the formatted text file Hasil.txt, which your question suggests.
read(1,*)(h(i,j)),j=1,jm) implies each record (line of text) has "jm" values, which is 1 value per line. Is this what the file looks like ? (An unknown number of blank lines will be skipped with this read (lu,*) ... statement.)
You appear to be wanting to write this information to another file; HasilNN.txt using 33 format (1x, 344f10.6) which suggests 3441 characters per line, although your write statement will write only 1 value per line (as jm=1). This would be a very long line for a text file and probably difficult to manage outside the program. If you did wish to do this, you could achieve this with an implied do loop, such as:
write(2,33) ((h(i,j),j=1,jm),I=1,im)
A few comments:
using jm = 1 implies each row has only one value, which could be equivalently represented as a 1d vector "dimension h(im)", negating the need for j
File unit numbers 1 and 2 are typically reserved unit numbers for screen/keyboard. You would be better using units 11 and 12.
When devising this code, you need to address the record structure in the 2 files, as a simple vector could be used. You can control the line length with the format. A format of (1x,8f10.6) would create a record of 81 characters, which would be much easier to manage.
Format descriptor f10.6 also limits the range of values you can manage in the files. Values >= 1000 or <= -100 will overflow this format, while values smaller than 1.e-6 will be zero.
As #francescalus has noted, you have declared "h" as integer, but use a real format descriptor. This will produce an "Error : format-data mismatch" and has to be changed to what is expected in the file.
You should consider what you wish to achieve and adjust the code.
I want to generate a dynamic random variable like ASDF123 during Post request and it should range from 7 digit to 10 digit and it should be unique everytime(if in case 500 threads). This field is required to generate order numbers. I'm new to Jmeter so not much idea.
My Scenarios is like this: .> I have to generate a variable in combination of alphabets and letters(like this ->ASDF12345) for post then need to provide same variable to get to retrieve the same order for each thread. It is working fine if I generate random variable ie. minimum 1000 to max:9999 and passing same to post and get. But the req is that the order no. can be alphabets & numeric/numeric/alphabet. Please suggest how to proceed for the same. And yes everytime it should be unique.
You can use Functions as:
RandomString - First parameter how many characters (10 in your case) and second parameter choose your combination of alphabets and numbers:
${__RandomString(10,abcdefg1234567890)}
Use Random if alphabets can be constant, and then add a number with 7-10 digits:
ASF${__Random(1000000,1000000000)}
Or use JSR223 element to use Random in your programming language as Java/Groovy.
You can try this:
${__javaScript(Math.random().toString(36).toUpperCase().substring(16))}
In jmeter it must looks like this:
Basically, what I want to do is look at the range information of a unified diff and know exactly which lines of code I should pay attention to.
For instance, this:
## -1827,7 +1827,7 ##
This tells me that in total only 1 line has changed, because the diff shows 3 lines above and below the change (so 7 - 6 = 1), and it also points me to the line 1830 (i.e. 1827 + 3).
To be more pedantic, this particular range information actually tells me that at line 1830, a line was removed (-), and at line 1830 a line was added (+).
Or to make that more obvious consider this range information for another diff:
## -878,15 +878,13 ##
What this is telling me is that at line 881 (878 + 3) 9 lines were deleted (15 - 6), but at line 881 only 7 lines were added (13 - 6).
So the question is, using a regex or some other Ruby string method, how do I pull out the above information easily?
i.e. how do I easily pull out this info:
Both The line numbers (i.e. just the 1827 or 878), which I can then add + 3 to determine the actual inline number I care about. It has to be both because both lines may not always be identical.
The number of lines affected (aka the 7, 15 or 13 right after the , in the above examples)
While I do that, how do I make sure to track the operation (addition or deletion) for each of the operations.
I tried slicing the string and going directly for a character -- e.g. myString[3] which gives me -, but that's the only character it reliably works for because the line numbers can be 1, 10, 100, 1000, 10000, etc. So the only way is to just scan the string and then parse it.
Edit 1
To add some code to show what I have tried.
Assume I have the contents of a diff in a variable called #diff_lines:
#diff_lines.each do |diff_line|
if diff_line.start_with?("##")
del_line_num_start = diff_line.split(/## /).second.split.first.split(/-/).second.split(/,/).first.to_i + 3
num_deleted_lines = diff_line.split(/## /).second.split.first.split(/-/).second.split(/,/).second.to_i - 6
add_line_num_start = diff_line.split(/## /).second.split.second.split(/\+/).second.split(/,/).first.to_i + 3
num_added_lines = diff_line.split(/## /).second.split.second.split(/\+/).second.split(/,/).second.to_i - 6
As you can see, the above works....but it is quite horrendous to look at and is OBVIOUSLY not very DRY.
Ideally I would like to be able to achieve the same thing, but just cleaner.
The general idea is to write a regular expression that has capture groups in it ((...)) to pick apart that string into something useful. For example:
diff_line.match(/\A##\s+\-(\d+),(\d+)\s+\+(\d+),(\d+)\s+##/)
This yields a MatchData object on a successful match. You can then apply this to some variables like:
if (m = diff_line.match(...))
a_start, a_len, b_start, b_len = m[1..4].map(&:to_i)
end
Then you can do whatever computations you need to do with these numbers.
If you're ever having trouble visualizing what a regular expression does, try a tool like Rubular to better illustrate the internals.
This may be a easy question to answer but I am a bit stumped and I have not studied Smarty long enough to figure it out.
I need to display numbers in a 3 digit format, ie:
8 = 008
18 = 018
118 = 118
To add some context, basically I am trying to edit a Prestashop template (never touched smarty before this). Currently the price is displayed as 1.223.014 and I would like to separate the last three digits so that I can format it differently from the first part of the price. Thus I would be able to do something like
<span class="abc">1.223</span>.<span class="xyz">014</span>
Not sure if there is a easier way to do this but basically I am currently dividing the current price by 1000 (to eliminate the last 3 digits) and now I am stumped on how to get the last 3 digits (works fine if the last three digits are above 99)
Your help is appreciated.
Thanks
Solution for your example
{"%03d"|sprintf:8}
Possible solution if you want the last 3 digits in any case
{'1.223.014'|substr:-3}
html:
<span class="abc">{'1.223.014'|substr:0:-4}</span>.<span class="xyz">{'1.223.014'|substr:-3}</span>
Note: This will not work if the number length is lower than 4
If you wanna check if there are dots inside the number, you can do this
{if '1.223.014'|substr_count:'.' > 0}
..dots inside..
{else}
..no dots inside..
{/if}
Tested with smarty 3.
I'm trying to read files and create a hashmap of the contents, but I'm having trouble at the parsing step. An example of the text file is
put 3
returns 3
between
3
pargraphs 1
4
3
#foo 18
****** 2
The word becomes the key and the number is the value. Notice that the spacing is fairly erratic. The word isn't always a word (which doesn't get picked up by /\w+/) and the number associated with that word isn't always on the same line. This is why I'm calling it not well-formed. If there were one word and one number on one line, I could just split it, but unfortunately, this isn't the case. I'm trying to create a hashmap like this.
{"put"=>3, "#foo"=>18, "returns"=>3, "paragraphs"=>1, "******"=>2, "4"=>3, "between"=>3}
Coming from Java, it's fairly easy. Using Scanner I could just use scanner.next() for the next key and scanner.nextInt() for the number associated with it. I'm not quite sure how to do this in Ruby when it seems I have to use regular expressions for everything.
I'd recommend just using split, as in:
h = Hash[*s.split]
where s is your text (eg s = open('filename').read. Believe it or not, this will give you precisely what you're after.
EDIT: I realized you wanted the values as integers. You can add that as follows:
h.each{|k,v| h[k] = v.to_i}