2016-05-01 11:13:57 +02:00
<!DOCTYPE html>
< html lang = "en-us" >
2017-05-09 11:29:54 +02:00
2016-05-01 11:13:57 +02:00
< head >
2017-05-09 11:29:54 +02:00
< meta charset = "UTF-8" >
< title > Caught in the Net< / title >
< meta name = "viewport" content = "width=device-width, initial-scale=1" >
< meta name = "theme-color" content = "#157878" >
< link rel = "stylesheet" href = "/css/normalize.css" >
<!-- <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'> -->
< link rel = "stylesheet" href = "/fonts/opensans.css" >
< link rel = "stylesheet" href = "/css/cayman.css" >
2016-05-01 11:13:57 +02:00
< / head >
2017-05-09 11:29:54 +02:00
< body >
< section class = "page-header" >
< h1 class = "project-name" > Caught in the Net< / h1 >
< h2 class = "project-tagline" > La rete ti cattura ma libera il pensiero< / h2 >
< a class = "btn" href = "/" > Home< / a >
2017-05-09 12:17:48 +02:00
< a class = "btn" href = "/about/" > About me< / a >
2017-05-09 11:29:54 +02:00
< a class = "btn" href = "/archive/" > Archive< / a >
< a class = "btn" href = "/contattami/" > Contact me< / a >
< a class = "btn" href = "http://francescomecca.eu:3000/explore/repos" > Personal Git< / a >
< a class = "btn" href = "https://github.com/FraMecca" > Github< / a >
< a class = "btn" href = "/feed.xml" > RSS< / a >
2017-05-09 11:38:51 +02:00
< a class = "btn" href = "/curriculum/CV_Mecca_Francesco.pdf" > Curriculum< / a >
2017-05-09 11:29:54 +02:00
< / section >
2016-05-01 11:13:57 +02:00
2017-05-09 11:29:54 +02:00
< section class = "main-content" >
2016-05-01 11:13:57 +02:00
< div class = "post" >
< h1 class = "post-title" > The Buridan's donkey in python< / h1 >
< span class = "post-date" > 02 Apr 2016< / span >
< p > During the final weeks of my exam session I started reading a bit about python 3 using an excellent book: < a href = "http://www.diveintopython.net/" > Dive into Python< / a > .
When I noted that python uses the < a href = "https://en.wikipedia.org/wiki/Mersenne_Twister" > Mersenne Twister PRNG< / a > as well I decided to write another version of my < a href = "http://francescomecca.eu/index.php/archives/207" > Buridan' s donkey program< / a > .< / p >
< figure class = "highlight" > < pre > < code class = "language-python" data-lang = "python" > < span class = "kn" > import< / span > < span class = "nn" > random< / span > < span class = "o" > ,< / span > < span class = "nn" > sys< / span >
< span class = "k" > if< / span > < span class = "n" > __name__< / span > < span class = "o" > ==< / span > < span class = "s" > '__main__'< / span > < span class = "p" > :< / span >
< span class = "n" > args< / span > < span class = "o" > =< / span > < span class = "nb" > list< / span > < span class = "p" > ()< / span >
< span class = "k" > if< / span > < span class = "ow" > not< / span > < span class = "n" > sys< / span > < span class = "o" > .< / span > < span class = "n" > stdin< / span > < span class = "o" > .< / span > < span class = "n" > isatty< / span > < span class = "p" > ():< / span >
< span class = "k" > for< / span > < span class = "n" > line< / span > < span class = "ow" > in< / span > < span class = "n" > sys< / span > < span class = "o" > .< / span > < span class = "n" > stdin< / span > < span class = "p" > :< / span >
< span class = "k" > if< / span > < span class = "n" > line< / span > < span class = "p" > [< / span > < span class = "o" > -< / span > < span class = "mi" > 1< / span > < span class = "p" > ]< / span > < span class = "ow" > is< / span > < span class = "s" > '< / span > < span class = "se" > \n< / span > < span class = "s" > '< / span > < span class = "p" > :< / span >
< span class = "n" > line< / span > < span class = "o" > =< / span > < span class = "n" > line< / span > < span class = "p" > [:< / span > < span class = "o" > -< / span > < span class = "mi" > 1< / span > < span class = "p" > ]< / span >
< span class = "n" > args< / span > < span class = "o" > .< / span > < span class = "n" > append< / span > < span class = "p" > (< / span > < span class = "n" > line< / span > < span class = "p" > )< / span >
< span class = "k" > else< / span > < span class = "p" > :< / span >
< span class = "n" > args< / span > < span class = "o" > =< / span > < span class = "n" > sys< / span > < span class = "o" > .< / span > < span class = "n" > argv< / span > < span class = "p" > [< / span > < span class = "mi" > 1< / span > < span class = "p" > :]< / span >
< span class = "n" > argRange< / span > < span class = "o" > =< / span > < span class = "nb" > len< / span > < span class = "p" > (< / span > < span class = "n" > args< / span > < span class = "p" > )< / span >
< span class = "k" > for< / span > < span class = "n" > i< / span > < span class = "ow" > in< / span > < span class = "nb" > range< / span > < span class = "p" > (< / span > < span class = "n" > argRange< / span > < span class = "p" > ):< / span >
< span class = "k" > print< / span > < span class = "p" > (< / span > < span class = "nb" > str< / span > < span class = "p" > (< / span > < span class = "n" > i< / span > < span class = "o" > +< / span > < span class = "mi" > 1< / span > < span class = "p" > )< / span > < span class = "o" > +< / span > < span class = "s" > '.'< / span > < span class = "p" > ,< / span > < span class = "n" > args< / span > < span class = "o" > .< / span > < span class = "n" > pop< / span > < span class = "p" > (< / span > < span class = "n" > random< / span > < span class = "o" > .< / span > < span class = "n" > randrange< / span > < span class = "p" > (< / span > < span class = "mi" > 0< / span > < span class = "p" > ,< / span > < span class = "nb" > len< / span > < span class = "p" > (< / span > < span class = "n" > args< / span > < span class = "p" > ))))< / span > < / code > < / pre > < / figure >
< p > This script works in a different way than the one in c++.
Rather than shuffling a list made by the entries in the arguments, it pops randomly one entry from the list till the list is empty.< / p >
< p > Not satisfied enough, I wrote also a telegram bot using the < a href = "https://github.com/eternnoir/pyTelegramBotAPI" > telebot library< / a > that works as the script above but inside the telegram app.
The bot can be added to your contact list by simply searching for < a href = "http://telegram.me/duridan_donkey_bot" > @duridan_donkey_bot< / a > (yes, a typo!)< / p >
< p > All the code is opensource and can be found on my github page.< / p >
< p > Francesco Mecca< / p >
< / div >
2016-09-17 15:13:02 +02:00
<!-- <div class="related"> -->
<!-- <related - posts /> -->
<!-- <h2>Related Posts</h2> -->
<!-- <ul class="related - posts"> -->
2017-05-07 12:21:36 +02:00
<!-- -->
<!-- <li> -->
<!-- <h3> -->
<!-- <a href="/pescewanda/2017/05/07/latestage_handbrake/"> -->
<!-- Late Stage Capitalism meets FOSS -->
<!-- <small>07 May 2017</small> -->
<!-- </a> -->
<!-- </h3> -->
<!-- </li> -->
2017-03-22 13:07:09 +01:00
<!-- -->
<!-- <li> -->
<!-- <h3> -->
2017-03-22 19:38:23 +01:00
<!-- <a href="/pescewanda/2017/03/20/spazio - digitale - rant - facebook__eng/"> -->
2017-03-22 13:07:09 +01:00
<!-- Some shallow thoughts from my tiny virtual space -->
<!-- <small>20 Mar 2017</small> -->
<!-- </a> -->
<!-- </h3> -->
<!-- </li> -->
2017-02-24 07:32:48 +01:00
<!-- -->
<!-- <li> -->
<!-- <h3> -->
2017-03-17 20:54:44 +01:00
<!-- <a href="/pescewanda/2017/03/07/spazio - digitale - rant - facebook/"> -->
<!-- Breve riflessione dal mio piccolo mondo virtuale -->
<!-- <small>07 Mar 2017</small> -->
2017-02-24 07:32:48 +01:00
<!-- </a> -->
<!-- </h3> -->
<!-- </li> -->
2016-11-19 18:38:14 +01:00
<!-- -->
<!-- <li> -->
<!-- <h3> -->
<!-- <a href="/pescewanda/2016/11/15/machine - learning - PARTE3/"> -->
<!-- Capire il Machine Learning (parte 3) -->
<!-- <small>15 Nov 2016</small> -->
<!-- </a> -->
<!-- </h3> -->
<!-- </li> -->
2016-09-17 15:13:02 +02:00
<!-- -->
<!-- <li> -->
<!-- <h3> -->
2016-11-18 20:45:39 +01:00
<!-- <a href="/pescewanda/2016/11/11/machine - learning - PARTE2/"> -->
<!-- Capire il Machine Learning (parte 2) -->
<!-- <small>11 Nov 2016</small> -->
2016-09-17 15:13:02 +02:00
<!-- </a> -->
<!-- </h3> -->
<!-- </li> -->
<!-- -->
<!-- </ul> -->
<!-- </div> -->
2017-03-22 19:38:23 +01:00
2016-09-17 15:13:02 +02:00
2017-02-24 07:32:48 +01:00
2016-09-17 15:13:02 +02:00
2017-05-07 12:21:36 +02:00
2016-09-17 15:13:02 +02:00
2017-03-22 13:07:09 +01:00
2016-09-17 15:13:02 +02:00
2016-11-18 20:45:39 +01:00
2016-09-17 15:13:02 +02:00
2016-11-19 18:38:14 +01:00
2016-09-17 15:13:02 +02:00
2017-03-22 13:07:09 +01:00
2016-09-17 15:13:02 +02:00
2016-11-18 20:45:39 +01:00
2016-09-17 15:13:02 +02:00
2017-03-22 13:07:09 +01:00
2016-09-17 15:13:02 +02:00
2016-11-18 20:45:39 +01:00
2016-09-17 15:13:02 +02:00
2017-05-07 12:21:36 +02:00
2016-09-17 15:13:02 +02:00
2017-05-07 12:21:36 +02:00
2017-03-22 13:07:09 +01:00
2016-11-18 20:45:39 +01:00
2016-11-19 18:38:14 +01:00
2016-11-18 20:49:28 +01:00
2016-11-18 20:45:39 +01:00
2016-09-17 15:13:02 +02:00
2017-03-22 13:07:09 +01:00
2016-09-17 15:13:02 +02:00
2016-11-18 20:45:39 +01:00
2016-09-17 15:13:02 +02:00
2017-03-22 13:07:09 +01:00
2016-09-17 15:13:02 +02:00
2016-11-18 20:45:39 +01:00
2016-09-17 15:13:02 +02:00
2017-03-22 13:07:09 +01:00
2017-05-07 12:21:36 +02:00
2016-09-17 15:13:02 +02:00
2016-05-01 11:13:57 +02:00
2017-05-09 11:29:54 +02:00
< footer class = "site-footer" >
2017-05-09 12:19:54 +02:00
< span class = "site-footer-owner" > < a href = "http://francescomecca.eu" > Caught in the Net< / a > is maintained by < a href = "contattami" > Francesco Mecca< / a > .< / span >
2017-05-09 11:29:54 +02:00
< span > CC BY-SA 4.0 International.< / br > < / span >
< span class = "site-footer-credits" > < a href = "https://jekyllrb.com" > Jekyll< / a > , < a href = "https://github.com/jasonlong/cayman-theme" > Cayman theme< / a > .< / span >
< / footer >
< / section >
2016-05-01 11:13:57 +02:00
< / body >
< / html >