Sponsored Content
Top Forums Shell Programming and Scripting python code...convert to ksh or sh Post 302103917 by ghostdog74 on Monday 22nd of January 2007 10:09:17 AM
Old 01-22-2007
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)
Code:
NTRIALS = 10000
matches = 0

For these, they are the same as declaring shell variables
3)
Code:
for trial in range(NTRIALS): # Do a bunch of trials...
    taken = {} 
    for person in range(NPEOPLE): 
        day = random.randint(0, 365) 
        if day in taken:
            matches += 1 
            break # No need to look for more than one.
        taken[day] = 1

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)
Code:
x=`echo "$x + 1" | bc`

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:
Code:
taken = { 102:1 } # 102 generated from random.randint()

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

convert from ksh to bsh

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)
Discussion started by: Boyd Young
2 Replies

2. Shell Programming and Scripting

Need to convert ksh script to Perl

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)
Discussion started by: rahimm1
1 Replies

3. Shell Programming and Scripting

convert ksh to C program

Hi Guys...is there a way to convert a .ksh script to .C program..? (3 Replies)
Discussion started by: aggars
3 Replies

4. UNIX for Dummies Questions & Answers

convert a file from .ksh to .sh

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)
Discussion started by: vnspkumar
3 Replies

5. Shell Programming and Scripting

Convert Hex - KSH

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)
Discussion started by: LiorAmitai
4 Replies

6. Shell Programming and Scripting

Python script to convert date to iso format

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)
Discussion started by: vikatakavi
2 Replies

7. Shell Programming and Scripting

Convert int to string in python

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)
Discussion started by: rossi
7 Replies

8. Shell Programming and Scripting

Convert excel to csv in python date not display exactly

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)
Discussion started by: fspalero
1 Replies

9. Shell Programming and Scripting

Can someone convert this python script to perl

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)
Discussion started by: azdps
1 Replies

10. UNIX for Beginners Questions & Answers

How to convert dec to hex in python?

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)
Discussion started by: bigvito19
9 Replies
DH_PYTHON(1)							     Debhelper							      DH_PYTHON(1)

NAME
dh_python - calculates Python dependencies and adds postinst and prerm Python scripts (deprecated) SYNOPSIS
dh_python [debhelperoptions] [-n] [-V version] [moduledirs...] DESCRIPTION
Note: This program is deprecated. You should use dh_python2 instead. This program will do nothing if debian/pycompat or a Python-Version control file field exists. dh_python is a debhelper program that is responsible for generating the ${python:Depends} substitutions and adding them to substvars files. It will also add a postinst and a prerm script if required. The program will look at Python scripts and modules in your package, and will use this information to generate a dependency on python, with the current major version, or on pythonX.Y if your scripts or modules need a specific python version. The dependency will be substituted into your package's control file wherever you place the token ${python:Depends}. If some modules need to be byte-compiled at install time, appropriate postinst and prerm scripts will be generated. If already byte- compiled modules are found, they are removed. If you use this program, your package should build-depend on python. OPTIONS
module dirs If your package installs Python modules in non-standard directories, you can make dh_python check those directories by passing their names on the command line. By default, it will check /usr/lib/site-python, /usr/lib/$PACKAGE, /usr/share/$PACKAGE, /usr/lib/games/$PACKAGE, /usr/share/games/$PACKAGE and /usr/lib/python?.?/site-packages. Note: only /usr/lib/site-python, /usr/lib/python?.?/site-packages and the extra names on the command line are searched for binary (.so) modules. -V version If the .py files your package ships are meant to be used by a specific pythonX.Y version, you can use this option to specify the desired version, such as 2.3. Do not use if you ship modules in /usr/lib/site-python. -n, --noscripts Do not modify postinst/prerm scripts. CONFORMS TO
Debian policy, version 3.5.7 Python policy, version 0.3.7 SEE ALSO
debhelper(7) This program is a part of debhelper. AUTHOR
Josselin Mouette <joss@debian.org> most ideas stolen from Brendan O'Dea <bod@debian.org> 9.20120909 2011-12-06 DH_PYTHON(1)
All times are GMT -4. The time now is 03:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy