I am not much familiar with python..I found this small script in python I even do not have python on my computer...can anyone help me out to convert this into ksh or sh..
PLEASE any help I will appreciate..
here is python code..
#!/usr/bin/env python
import random # Get a random number generator.
NTRIALS = 10000 # Enough trials to get an reasonably accurate answer.
NPEOPLE = 30 # How many people in the group?
matches = 0 # Keep track of how many trials have matching birthdays.
for trial in range(NTRIALS): # Do a bunch of trials...
taken = {} # A place to keep track of which birthdays
# are already taken on this trial.
for person in range(NPEOPLE): # Put the peoples birthdays down, one at a time...
day = random.randint(0, 365) # On a randomly chosen day.
if day in taken:
matches += 1 # A match!
break # No need to look for more than one.
taken[day] = 1 # Mark the day as taken.
I wanted to see how does it work...I have no experience in python that is why I ask if anyone can help me out to compile it thru ksh or sh...
I would not like to install python..I would prefare if someone can help me out with his..becouse I plan to upgrade this method..and add new modules in shell..??
This Python script is very clear in what its supposed to do.
1) import random
This is a library to generate random numbers
In bash , you can use the RANDOM env variable
2)
For these, they are the same as declaring shell variables
3)
range(NTRIALS) will give you a range of values from 0 to 9999
so for trial in range(NTRIALs) is a for loop to generate these numbers. So this for loop will iterate 10000 times, starting from count 0.
matches+=1 is the same as matches = matches + 1, which in shell, you can use something like this (or other methods)
taken = {} declares a dictionary, or a lookup table.
random.randint(0,365) will generate a random number in the range from 0 to 365. taken[day] = 1 means keep that random day number in the dictionary
with the value of 1.
taken will now contain for example:
When I try to convert big numbers I get extra numbers at the end that doesn't move plus an L character too. How to remove the 4 extra characters at the end 000L?
8b8dbbc584d9c000L
8b8dc4ddd34c6000L
8b8dcdf621bf0000L
8b8dd70e7031a000L
8b8de026bea44000L
#!/usr/bin/python
... (9 Replies)
There is a python script that I would like converted to a perl script. If someone has the time to convert the script I would appreciate it. You can find the script below:
reboot-mb8600/reboot-mb8600.py at master . j4m3z0r/reboot-mb8600 . GitHub
#!/usr/bin/python
'''
A hacky script to... (1 Reply)
Hi,
Anyone can help I am just converting the excel file to csv using python, I can get the conversion output but the date not display exactly.
test.xlsx date format
167 1588 risks/SCS JP CAMPANA & CIE.pdf SCS JP CAMPANA & CIE 2 1 1 0 2015-03-16 16:56:25
167 1146 risks/AirBNB... (1 Reply)
Hi,
I have column 5 in a file which contains string like this for ex.
RP11-125O5.2
SLCO1B1
CAPN1
FRMPD2
TXNL4B
So I do by
data = )]
ValueError: invalid literal for int() with base 10: 'R'
Can someday tell me how to convert this column into int successfully.
Thank You in... (7 Replies)
Hi ,
This is my 1st program in python never tried any python before.
i am trying to write a python script which reads a .tsv file line by line and in each line it should look for mm/dd/yyyy formate and convert it to yyyy-mm-dd formate . can some one provide be some sample code to do that. (2 Replies)
Hello,
I woild like to convert hex on KSH not BASH:
I tried to use:
tmp=31
printf "\x"${tmp}""
it works on bash - Output is '1' but not on ksh.
please advice on the right syntax.
Thanks. (4 Replies)
hi
I have written a shell scrpit in .ksh mode. I need to convert this scritp to .sh. What things i need to check while converting the file from .ksh to .sh.
Could you please help me out.
Thanks&Reagdrs
Pavan Kumar (3 Replies)
Guys I am new to this forum, this may seem like a cheeky request.
I have been asked by my manager to convert this ksh script to Perl. I do not have the foggiest about Perl and would appreciate any help on this.
Basically this scipt automates a recovery process for EMC Legato Networker. It will... (1 Reply)
How difficult is it to convert from bourn shell to korn shell and visversa.
Reason: If someone bombsout or logs out incorrectly the application we are using give the next person to log in the same permissions as the person that bombed out. Therefore createing ownership problems on print files. (2 Replies)