- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: python code...convert to ksh or sh
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2007 07:31 PM
01-21-2007 07:31 PM
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 people’s 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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2007 08:02 PM
01-21-2007 08:02 PM
Re: python code...convert to ksh or sh
If you do not have python on your machine, you are not riunning the codse currently, so why do you want to port it ?
You can use the Random Number Generator (RNG)product:
http://h20293.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=KRNG11I
Your python code comes from:
kochanski.org/gpk/./teaching/0501Oxford/MonteCarlo.pdf
Could you also please revisit your previous threads and tidy them up (award points and close), for example:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1086922
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2007 08:30 PM
01-21-2007 08:30 PM
Re: python code...convert to ksh or sh
Bingo..yes my code comes from that page..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..??
Regards..any help is very welcome????
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2007 08:35 PM
01-21-2007 08:35 PM
Re: python code...convert to ksh or sh
I still hope I will get more help on this one?!?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2007 12:59 AM
01-22-2007 12:59 AM
SolutionI remember discussing "the birthday" problem in one of my CS classes...
#!/usr/bin/sh
typeset -i NTRIALS=10000
typeset -i NPEOPLE=30
set -A TAKEN
typeset -i MATCHES=0
typeset -i CURTRIAL=0
typeset -i DAY
while [[ ${CURTRIAL} -lt ${NTRIALS} ]]
do
DAY=$(( ${RANDOM}%365 ))
if [[ ${TAKEN[${DAY}]:--1} -gt 0 ]]
then
MATCHES=$(( ${MATCHES}+1 ))
TAKEN[${DAY}]=$(( ${TAKEN[${DAY}]}+1 ))
else
TAKEN[${DAY}]=1
fi
#echo "Trial: ${CURTRIAL} Day: ${DAY} Matches: ${MATCHES}"
CURTRIAL=$(( ${CURTRIAL}+1 ))
done
echo "Matches: ${MATCHES}"
exit 0
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2007 05:43 PM
01-22-2007 05:43 PM
Re: python code...convert to ksh or sh
Regards..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2007 05:43 PM
01-22-2007 05:43 PM