Popular Python recipes tagged "simulation"http://code.activestate.com/recipes/langs/python/tags/simulation/2016-07-17T17:26:47-07:00ActiveState Code RecipesThe many uses of randomness - Part 2 (Python)
2016-07-17T17:26:47-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580690-the-many-uses-of-randomness-part-2/
<p style="color: grey">
Python
recipe 580690
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/random/">random</a>, <a href="/recipes/tags/random_number/">random_number</a>, <a href="/recipes/tags/simulation/">simulation</a>, <a href="/recipes/tags/testing/">testing</a>).
</p>
<p>This is the second recipe in the series about the uses of randomness in Python. The first recipe is here:</p>
<p><a href="https://code.activestate.com/recipes/580674-the-many-uses-of-randomness-part-1/?in=user-4173351" rel="nofollow">https://code.activestate.com/recipes/580674-the-many-uses-of-randomness-part-1/?in=user-4173351</a></p>
<p>This second recipe shows some uses of random numbers to generate random characters and random strings of various categories, and some purposes for which these generated strings can be used in testing.</p>
Reaction Diffusion Simulation (Python)
2015-10-16T19:52:02-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/579114-reaction-diffusion-simulation/
<p style="color: grey">
Python
recipe 579114
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/chaos/">chaos</a>, <a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/images/">images</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/physics/">physics</a>, <a href="/recipes/tags/simulation/">simulation</a>).
Revision 2.
</p>
<p>Reaction-Diffusion Simulation using Gray-Scott Model.</p>
2D Fluid Simulation using FHP LGCA (Python)
2014-08-18T05:01:04-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578924-2d-fluid-simulation-using-fhp-lgca/
<p style="color: grey">
Python
recipe 578924
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/physics/">physics</a>, <a href="/recipes/tags/simulation/">simulation</a>).
</p>
<p>2D Fluid Simulation using FHP LGCA (Lattice Gas Cellular Automata)</p>
<p>Simulates fluid flow in a circular channel.</p>
<p>It works really slow but I think it can be a lot faster if it modified for NumPy and possibly Py2Exe.</p>
<p>But my main goal was to provide easy to understand code (not performance) anyway. </p>
Automated Stock Market Trading Simulation (Python)
2014-05-16T02:40:28-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578881-automated-stock-market-trading-simulation/
<p style="color: grey">
Python
recipe 578881
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/simulation/">simulation</a>, <a href="/recipes/tags/stock/">stock</a>, <a href="/recipes/tags/stock_market/">stock_market</a>).
</p>
<p>It simulates an automated trading strategy against a simulated stock.</p>
<p>I think the results are interesting.
It seems number of wins are always higher than number of losses
but average amount of loss is also always higher than average amount of win! </p>
Creature Population Simulator (Python)
2013-08-15T03:22:24-07:00Damian Estebanhttp://code.activestate.com/recipes/users/4187532/http://code.activestate.com/recipes/578641-creature-population-simulator/
<p style="color: grey">
Python
recipe 578641
by <a href="/recipes/users/4187532/">Damian Esteban</a>
(<a href="/recipes/tags/creation/">creation</a>, <a href="/recipes/tags/populate/">populate</a>, <a href="/recipes/tags/simulation/">simulation</a>).
</p>
<p>After wondering how human populations can increase in size and writing a simulator for the problem, a simpler question came to mind regarding a population without death. This creature population simulator is an old experiment that served its purpose well. The code here is committed for archival to be run under Python 2.5 or later versions.</p>
Gravner-Griffeath Snowflake Simulation (Python)
2013-05-27T00:13:09-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578533-gravner-griffeath-snowflake-simulation/
<p style="color: grey">
Python
recipe 578533
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/physics/">physics</a>, <a href="/recipes/tags/simulation/">simulation</a>).
Revision 2.
</p>
<p>Gravner-Griffeath snowflake simulation.</p>
<p>For better results increase the image size and number of growth steps and prepare to wait!</p>
War Card Game Simulation (Python)
2012-07-01T01:23:03-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578179-war-card-game-simulation/
<p style="color: grey">
Python
recipe 578179
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/automatically/">automatically</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/simulation/">simulation</a>).
</p>
<p>After playing the card game with people for the first time, the game turned out to be rather boring. The way we played took absolutely no thought whatsoever and turned out to be very easy to automate. The game below is configured for four different players to complete the simple game until it ends. Each player's hand in printed, and the cards played in each round is shown till someone finishes. Whoever wins is shown at the end of the simulation, and the program quickly exits when complete.</p>
Human Population Simulator (Python)
2012-07-13T14:37:26-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578208-human-population-simulator/
<p style="color: grey">
Python
recipe 578208
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/archive/">archive</a>, <a href="/recipes/tags/human/">human</a>, <a href="/recipes/tags/old/">old</a>, <a href="/recipes/tags/populate/">populate</a>, <a href="/recipes/tags/simulation/">simulation</a>).
Revision 2.
</p>
<p>After wondering about how populations can increase in size, a simulator was written with a very simplistic model for total human growth. This is the result of an old experiment and served its purpose well at the time. This is committed for archival to be run under Python 2.5 or later versions.</p>
Creature Population Simulator (Python)
2012-08-16T03:16:24-07:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/578240-creature-population-simulator/
<p style="color: grey">
Python
recipe 578240
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/creation/">creation</a>, <a href="/recipes/tags/populate/">populate</a>, <a href="/recipes/tags/simulation/">simulation</a>).
</p>
<p>After wondering how human populations can increase in size and writing a simulator for the problem, a simpler question came to mind regarding a population without death. This creature population simulator is an old experiment that served its purpose well. The code here is committed for archival to be run under Python 2.5 or later versions.</p>
Spring-Mass System Simulation (Python)
2011-05-02T01:59:45-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577681-spring-mass-system-simulation/
<p style="color: grey">
Python
recipe 577681
by <a href="/recipes/users/4172570/">FB36</a>
(<a href="/recipes/tags/chaos/">chaos</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/physics/">physics</a>, <a href="/recipes/tags/simulation/">simulation</a>).
</p>
<p>It simulates a damped spring-mass system driven by sinusoidal force.</p>
Pendulum Simulation with Turtle (Python)
2011-01-27T22:59:54-08:00Stephen Chappellhttp://code.activestate.com/recipes/users/2608421/http://code.activestate.com/recipes/577553-pendulum-simulation-with-turtle/
<p style="color: grey">
Python
recipe 577553
by <a href="/recipes/users/2608421/">Stephen Chappell</a>
(<a href="/recipes/tags/demonstration/">demonstration</a>, <a href="/recipes/tags/simulation/">simulation</a>, <a href="/recipes/tags/turtle/">turtle</a>).
</p>
<p>This program was written per R.T.Giles's second assignment in 10COF180 (November 25, 2010). A student under his instruction wanted help writing a program, and while not required, a GUI was placed on the program's output to visually demonstrate what was taking place within the program. The recipe below provides a simple simulation of a undamped pendulum and produces a visual representation for about thirty seconds. The code could be greatly improved but gives a demonstration of what a few turtle commands can do in Python. Very little code must be written to produce graphics on the computer screen.</p>
"More Sex is Safer Sex" Paradox (Python)
2010-09-22T02:56:37-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/577403-more-sex-is-safer-sex-paradox/
<p style="color: grey">
Python
recipe 577403
by <a href="/recipes/users/4076953/">Jack Trainor</a>
(<a href="/recipes/tags/educational/">educational</a>, <a href="/recipes/tags/simulation/">simulation</a>).
</p>
<p>In his book, "More Sex Is Safer Sex: The Unconventional Wisdom of Economics, " Steven Landsburg argues that if sexual conservatives took more sexual partners it would improve everyone's chances of finding low-risk partners, thereby reducing the spread of STDs for all. </p>
<p>See <a href="http://www.nytimes.com/2007/07/08/books/chapters/0708-1st-land.html?_r=1&pagewanted=print" rel="nofollow">http://www.nytimes.com/2007/07/08/books/chapters/0708-1st-land.html?_r=1&pagewanted=print</a> .</p>
<p>This recipe attempts to simulate the scenario which Landsburg describes and test his claim that "More sex is safer sex."</p>
Attribute-based Framework 1: Basics (Python)
2010-07-21T21:40:54-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/577327-attribute-based-framework-1-basics/
<p style="color: grey">
Python
recipe 577327
by <a href="/recipes/users/4076953/">Jack Trainor</a>
(<a href="/recipes/tags/educational/">educational</a>, <a href="/recipes/tags/framework/">framework</a>, <a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/simulation/">simulation</a>).
Revision 2.
</p>
<p>I am adapting Prof. David Cheriton's OO software methodology to Python. It's an approach for building industrial-strength code with a disciplined architecture, consistent naming conventions, and a rigorous division of interface from implementation. I'll be adding more of his techniques in further recipes. These recipes are based on Cheriton's CS249a course at Stanford.</p>
Attribute-based Framework 2: Notifications (Python)
2010-07-23T20:12:10-07:00Jack Trainorhttp://code.activestate.com/recipes/users/4076953/http://code.activestate.com/recipes/577330-attribute-based-framework-2-notifications/
<p style="color: grey">
Python
recipe 577330
by <a href="/recipes/users/4076953/">Jack Trainor</a>
(<a href="/recipes/tags/educational/">educational</a>, <a href="/recipes/tags/framework/">framework</a>, <a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/simulation/">simulation</a>).
Revision 2.
</p>
<p>I am adapting Prof. David Cheriton's OO software methodology to Python. It's an approach for building industrial-strength code with a disciplined architecture, consistent naming conventions, and a rigorous division of interface from implementation. I'll be adding more of his techniques in further recipes. These recipes are based on Cheriton's CS249a course at Stanford.</p>