Edit executavble command to make random number generator in Perl - perl

I was using this module for Perl, Crypt::PRNG, to generate random numbers. The number-generation seems truly random when using the random string command, it can use digits 0-9 as well as other characters and create a random string of the specified number of digits, the problem is the leading 0's.
perl -MCrypt::PRNG=:all -E "say random_string_from("1234567890", n)"
where n is the number of digits, is there a executable command similar to the one above to fix the leading 0's so I can for sure get an n digit number? My intent is to fix only the first digit to "123456789". Does anyone know how to do this? Thanks in advance.

How about
random_string_from("123456789", 1) . random_string_from("1234567890", $n-1)

Put the Crypt::PRNG code in a while loop until the leading character is not a 0.

Related

What is the numbers separator when comma is used as decimal separator?

As we know, in many places people use comma as decimal separator. My question is: how they write a formula such as sum(1, 2, 3)? I don't know how people there separate numbers in that formula.
I finally use a semi-colon “;” as a universal solution.

How to trim leading zeros in List & Label?

Does anyone know if it's possible to trim irregular numbers in List & Label? I need to remove leading 00 from a number. Can't seem to find any function to solve my problem. Only trimming spaces or replacing strings.
Starting with version 25, stripping arbitrary characters from strings using Atrim$() is supported. Until then, if you want to get rid of leading zeroes in a string, you might use something like Str$(ToNumber(yourStringField),0,0) where the last argument is the required precision in digits.

matlab textscan gives me wrong number of lines

I have a file names inputR_revised.tsv at https://www.dropbox.com/s/vtby4027rvprhga/inputR_revised.tsv?dl=0
In matlab, I typed
fid=fopen('BMC3C/example/inputR_revised.tsv','r')
covTable = textscan(fid,['%s',repmat('%.8n',[1,20])],'HeaderLines',1);
I get covTable{1,1} of size 41699 times 1. However when I type the following at terminal
wc -l inputR_revised.tsv
I get 41677.
Why does it differ? I have used sed and cut to modify the original file to get inputR_revised.tsv. Is this the reason?
Is there a way to fix this?
%.8 is not enough if you have decimals printed with more than 8 digits. For these cases digits after the 8th decimal could be treated as a separate entry. That will make more numbers than expected. You should use a higher value for number of decimals in the scan format. For example,
fid=fopen('BMC3C/example/inputR_revised.tsv','r')
covTable = textscan(fid,['%s',repmat('%.18n',[1,20])],'HeaderLines',1);
This should give you the correct number of rows.

How can i get 6 digits after comma (matlab)?

I read from text some comma seperated values.
-8.618643,41.141412
-8.639847,41.159826
...
I write script below;
get_in = zeros(lendata,2);
nums = str2num(line); % auto comma seperation.(two points)
for x=1:2
get_in(i,x)=nums(x);
end
it automatically round numbers. For example;
(first row convert to "-8.6186 , 41.1414")
How can i ignore round operation?
I want to get 6 digits after comma.
I tried "str2double" after split line with comma delimeter.
I tried import data tool
But it always rounded to 4 digits, too.
As one of the replies has already said, the values aren't actually rounded, just the displayed values (for ease of reading them). As suggested, if you just enter 'format long' into the command window that should help.
The following link might help with displaying individual values to certain decimal places though: https://uk.mathworks.com/matlabcentral/newsreader/view_thread/118222
It suggests using the sprintf function. For example sprintf(%4.6,data) would display the value of 'data' to 6 decimal places.

Generating Combinations using Perl

I need to write a Perl routine that will generate the n choose k combinations of a given set. I don't need to count how many sets there are, I have to be able to print them out. I'm pretty stumped.
Any advice is appreciated.
Regards.
There's a module called Math::Combinatorics that produces combinations (nCr), permutations (nPr), and derangements of any set of things that you provide to it.
If you want combinations without repetition, you can generate all binary numbers to length k, select those that have n 1's and apply them to the set in a fixed order: 0 means not selected, 1 means selected. To get a binary number, use sprintf '%05b'; to count 1's use tr/1//.