From d71c0fd36ba2cb1c84d70acd19806189a1ae98e9 Mon Sep 17 00:00:00 2001 From: Laird Streak Date: Tue, 16 Feb 2021 18:52:07 +1300 Subject: [PATCH 1/8] Add formated and linted update --- 01 Acey Ducey/python/README.md | 2 + 01 Acey Ducey/python/acey_ducey.py | 4 +- 01 Acey Ducey/python/aceyducey.py | 86 +++++++++++++++++------------- 3 files changed, 53 insertions(+), 39 deletions(-) diff --git a/01 Acey Ducey/python/README.md b/01 Acey Ducey/python/README.md index 781945ec..e5e1f207 100644 --- a/01 Acey Ducey/python/README.md +++ b/01 Acey Ducey/python/README.md @@ -1,3 +1,5 @@ Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html) Conversion to [Python](https://www.python.org/about/) + +Propose using pylint and black to format python files so that it conforms to some standards diff --git a/01 Acey Ducey/python/acey_ducey.py b/01 Acey Ducey/python/acey_ducey.py index ad779a5d..6832c7e0 100644 --- a/01 Acey Ducey/python/acey_ducey.py +++ b/01 Acey Ducey/python/acey_ducey.py @@ -24,6 +24,7 @@ cards = { def play_game(): + """Play the game""" cash = 100 while cash > 0: print(f"You now have {cash} dollars\n") @@ -63,6 +64,7 @@ def play_game(): def main(): + """Main""" keep_playing = True while keep_playing: @@ -75,7 +77,7 @@ if __name__ == "__main__": print( """ Acey-Ducey is played in the following manner -The dealer (computer) deals two cards face up +The dealer (computer) deals two cards face up You have an option to be or not bet depending on whether or not you feel the card will have a value between the first two. diff --git a/01 Acey Ducey/python/aceyducey.py b/01 Acey Ducey/python/aceyducey.py index c995b836..9aaef681 100644 --- a/01 Acey Ducey/python/aceyducey.py +++ b/01 Acey Ducey/python/aceyducey.py @@ -1,3 +1,4 @@ +"""aceyducey.py contains game code""" ######################################################## # # Acey Ducey @@ -31,18 +32,34 @@ DEFAULT_BANKROLL = 100 # functions def deal_card_num(): + """Get card number""" return random.randint(0, 12) -def get_card_name(n): - cardNames = (" 2", " 3", " 4", " 5", " 6", \ - " 7", " 8", " 9", " 10", "Jack", \ - "Queen", "King", "Ace") - return(cardNames[n]) -def display_bankroll(b): - if bankroll > 0: - print("You now have %s dollars\n"%b) - +def get_card_name(number): + """Get card name""" + card_names = ( + " 2", + " 3", + " 4", + " 5", + " 6", + " 7", + " 8", + " 9", + " 10", + "Jack", + "Queen", + "King", + "Ace", + ) + return card_names[number] + + +def display_bankroll(bank_roll): + """Print current bankroll""" + if BANK_ROLL > 0: + print("You now have %s dollars\n" % bank_roll) # Display initial title and instructions @@ -58,15 +75,15 @@ print("If you do not want to bet, input a 0") # Loop for series of multiple games -keep_playing = True -while keep_playing: - +KEEP_PLAYING = True +while KEEP_PLAYING: + # Initialize bankroll at start of each game - bankroll = DEFAULT_BANKROLL - display_bankroll(bankroll) + BANK_ROLL = DEFAULT_BANKROLL + display_bankroll(BANK_ROLL) # Loop for a single round. Repeat until out of money. - while bankroll > 0: + while BANK_ROLL > 0: # Deal out dealer cards print("Here are your next two cards") @@ -76,46 +93,46 @@ while keep_playing: while dealer1 == dealer2: dealer2 = deal_card_num() # Organize the cards in order if they're not already - if (dealer1 >= dealer2): - (dealer1, dealer2) = (dealer2, dealer1) # Ya gotta love Python! + if dealer1 >= dealer2: + (dealer1, dealer2) = (dealer2, dealer1) # Ya gotta love Python! # Show dealer cards to the player # (use card name rather than internal number) print(get_card_name(dealer1)) print(get_card_name(dealer2) + "\n") # Get and handle player bet choice - bet_is_valid = False - while not bet_is_valid: + BET_IS_VALID = False + while not BET_IS_VALID: curr_bet = input("What is your bet? ") try: curr_bet = int(curr_bet) - except: + except ValueError: # Bad input? Just loop back up and ask again... pass else: if curr_bet == 0: - bet_is_valid = True + BET_IS_VALID = True print("Chicken!!\n") - elif curr_bet > bankroll: + elif curr_bet > BANK_ROLL: print("Sorry, my friend but you bet too much") - print("You have only %s dollars to bet\n" % bankroll) + print("You have only %s dollars to bet\n" % BANK_ROLL) else: # Deal player card - bet_is_valid = True + BET_IS_VALID = True player = deal_card_num() print(get_card_name(player)) - + # Did we win? - if player > dealer1 and player < dealer2: + if dealer1 < player < dealer2: print("You win!!!") - bankroll += curr_bet + BANK_ROLL += curr_bet else: print("Sorry, you lose") - bankroll -= curr_bet + BANK_ROLL -= curr_bet # Update player on new bankroll level - display_bankroll(bankroll) - + display_bankroll(BANK_ROLL) + # End of loop for a single round print("\n\nSorry, friend but you blew your wad") @@ -123,7 +140,7 @@ while keep_playing: if player_response.lower() == "yes": print() else: - keep_playing = False + KEEP_PLAYING = False # End of multiple game loop @@ -187,10 +204,3 @@ print("OK Hope you had fun\n") # get their own player card dealt). # ######################################################## - - - - - - - From 5fc593ff727f90016636439a558fc5950ada6e00 Mon Sep 17 00:00:00 2001 From: Les Orchard Date: Mon, 15 Feb 2021 23:29:14 -0800 Subject: [PATCH 2/8] Implemented Sine Wave in JavaScript --- 78 Sine Wave/javascript/sinewave.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 78 Sine Wave/javascript/sinewave.js diff --git a/78 Sine Wave/javascript/sinewave.js b/78 Sine Wave/javascript/sinewave.js new file mode 100644 index 00000000..3823273d --- /dev/null +++ b/78 Sine Wave/javascript/sinewave.js @@ -0,0 +1,22 @@ +print(tab(30), "SINE WAVE"); +print(tab(15), "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"); +print("\n\n\n\n"); + +// REMARKABLE PROGRAM BY DAVID AHL +// Transliterated to Javascript by Les Orchard + +let toggleWord = true; + +for (let step = 0; step < 40; step += 0.25) { + let indent = Math.floor(26 + 25 * Math.sin(step)); + print(tab(indent), toggleWord ? "CREATIVE" : "COMPUTING"); + toggleWord = !toggleWord; +} + +function print(...messages) { + console.log(messages.join(" ")); +} + +function tab(count) { + return " ".repeat(count); +} From c4e3f93b800569e13cb6b2ba822fe114543c8b40 Mon Sep 17 00:00:00 2001 From: drbaggy Date: Tue, 16 Feb 2021 08:36:15 +0000 Subject: [PATCH 3/8] added in depth charge in perl --- 31 Depth Charge/perl/README.md | 17 +++++++++ 31 Depth Charge/perl/depth-charge.pl | 52 ++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 31 Depth Charge/perl/README.md create mode 100644 31 Depth Charge/perl/depth-charge.pl diff --git a/31 Depth Charge/perl/README.md b/31 Depth Charge/perl/README.md new file mode 100644 index 00000000..6c2756f8 --- /dev/null +++ b/31 Depth Charge/perl/README.md @@ -0,0 +1,17 @@ +Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html) + +Conversion to [Perl](https://www.perl.org/) + +## Conversion + +Not a difficult conversion - but a chance to throw in a few ways +Perl makes life easy. + + * To get the sub permission which is a random location in the g x g x g grid we can use: + * assigning multiple variables in list form ($a,$b,$c) = (?,?,?) + * where the list on the right hand side is generated with a map function + + * We use ternarys to generate the message if you miss the sub. + * We use join to stitch the pieces of the string together. + * If we have a ternary where we don't want to return anything we return an empty list rather than an empty string - if you return the latter you still get the padding spaces. + diff --git a/31 Depth Charge/perl/depth-charge.pl b/31 Depth Charge/perl/depth-charge.pl new file mode 100644 index 00000000..51bd172c --- /dev/null +++ b/31 Depth Charge/perl/depth-charge.pl @@ -0,0 +1,52 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +print ' Depth Charge +Creative Computing Morristown, New Jersey + + +Depth Charge Game + +Dimensions of Search Area? '; + +my $g = ; +my $n = int( log($g) / log 2 ) + 1; +print ' +You are the captain of the Destroyer USS Computer +an enemy sub has been causing you trouble. Your +mission is to destroy it. You have ',$n,' shots. +Specify depth charge explosion point with a +trio of number -- the first two are the surface +co-ordinates; the third is the depth. +'; + +while(1) { ## Repeat until we say no.... + print "\nGood luck!\n\n"; + my ($a,$b,$c) = map { int rand $g } 1..3; ## Get the location + my $hit = 0; ## Keep track if we have won yet! + foreach ( 1..$n ) { + print "\nTrial # $_ ? "; + my ( $x, $y, $z ) = split m{\D+}, ; + if( $x==$a && $y==$b && $z==$c ) { + $hit = 1; ## We have won + print "\n\nB O O M ! ! You found it in $_ tries!\n"; + last; + } + print join q( ), 'Sonar reports show was', + $y < $b ? 'South' : $y > $b ? 'North' : (), + $x < $a ? 'West' : $x > $a ? 'East' : (), + $x == $a && $y == $b ? () : 'and' , + $z < $c ? 'too high' : $z > $c ? 'too low' : 'depth OK', + ".\n"; + } + + ## Only show message if we haven't won... + print "\nYou have been torpedoed! Abandon ship!\nThe submarine was at $a, $b, $c\n" unless $hit; + + print "\n\nAnother game (Y or N)? "; + last unless =~ m{Y}i; ## Y or y not typed so leave loop +} +## Say good bye +print "OK. Hope you enjoyed yourself.\n\n"; From 9e2a932a4a17c4e611ce7ae0e0147fde6d0faba9 Mon Sep 17 00:00:00 2001 From: Jeff Jetton Date: Tue, 16 Feb 2021 07:07:27 -0600 Subject: [PATCH 4/8] Initial commit in new repo --- 05 Bagels/java/BagelGame.java | 177 ++++++++++++++++++++++++++++++++++ 05 Bagels/java/Bagels.java | 129 +++++++++++++++++++++++++ 2 files changed, 306 insertions(+) create mode 100644 05 Bagels/java/BagelGame.java create mode 100644 05 Bagels/java/Bagels.java diff --git a/05 Bagels/java/BagelGame.java b/05 Bagels/java/BagelGame.java new file mode 100644 index 00000000..15dcf497 --- /dev/null +++ b/05 Bagels/java/BagelGame.java @@ -0,0 +1,177 @@ +/****************************************************************************** +* +* Encapsulates all the state and rules for one single game of Bagels +* +******************************************************************************/ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Random; +import java.util.Set; + +public class BagelGame { + + public static final String CORRECT = "FERMI FERMI FERMI"; + public static final int MAX_GUESSES = 20; + + enum GameState { + RUNNING, + WON, + LOST + } + + private GameState state = GameState.RUNNING; + private List secretNum; + private int guessNum = 1; + + public BagelGame() { + // No-arg constructor for when you don't need to set the seed + this(new Random()); + } + + public BagelGame(long seed) { + // Setting the seed as a long value + this(new Random(seed)); + } + + public BagelGame(Random rand) { + // This is the "real" constructor, which expects an instance of + // Random to use for shuffling the digits of the secret number. + + // Since the digits cannot repeat in our "number", we can't just + // pick three random 0-9 integers. Instead, we'll treat it like + // a deck of ten cards, numbered 0-9. + List digits = new ArrayList(10); + // The 10 specified initial allocation, not actual size, + // which is why we add rather than set each element... + for (int i = 0; i < 10; i++) { + digits.add(i); + } + // Collections offers a handy-dandy shuffle method. Normally it + // uses a fresh Random class PRNG, but we're supplying our own + // to give us controll over whether or not we set the seed + Collections.shuffle(digits, rand); + + // Just take the first three digits + secretNum = digits.subList(0, 3); + } + + public boolean isOver() { + return state != GameState.RUNNING; + } + + public boolean isWon() { + return state == GameState.WON; + } + + public int getGuessNum() { + return guessNum; + } + + public String getSecretAsString() { + // Convert the secret number to a three-character string + String secretString = ""; + for (int n : secretNum) { + secretString += n; + } + return secretString; + } + + @Override + public String toString() { + // Quick report of game state for debugging purposes + String s = "Game is " + state + "\n"; + s += "Current Guess Number: " + guessNum + "\n"; + s += "Secret Number: " + secretNum; + return s; + } + + public String validateGuess(String guess) { + // Checks the passed string and returns null if it's a valid guess + // (i.e., exactly three numeric characters) + // If not valid, returns an "error" string to display to user. + String error = ""; + + if (guess.length() == 3) { + // Correct length. Are all the characters numbers? + try { + Integer.parseInt(guess); + } catch (NumberFormatException ex) { + error = "What?"; + } + if (error == "") { + // Check for unique digits by placing each character in a set + Set uniqueDigits = new HashSet(); + for (int i = 0; i < guess.length(); i++){ + uniqueDigits.add(guess.charAt(i)); + } + if (uniqueDigits.size() != guess.length()) { + error = "Oh, I forgot to tell you that the number I have in mind\n"; + error += "has no two digits the same."; + } + } + } else { + error = "Try guessing a three-digit number."; + } + + return error; + } + + public String makeGuess(String s) throws IllegalArgumentException { + // Processes the passed guess string (which, ideally, should be + // validated by previously calling validateGuess) + // Return a response string (PICO, FERMI, etc.) if valid + // Also sets game state accordingly (sets win state or increments + // number of guesses) + + // Convert string to integer list, just to keep things civil + List guess = new ArrayList(3); + for (int i = 0; i < 3; i++) { + guess.add((int)s.charAt(i) - 48); + } + + // Build response string... + String response = ""; + // Correct digit, but in wrong place? + for (int i = 0; i < 2; i++) { + if (secretNum.get(i) == guess.get(i+1)) { + response += "PICO "; + } + if (secretNum.get(i+1) == guess.get(i)) { + response += "PICO "; + } + } + if (secretNum.get(0) == guess.get(2)) { + response += "PICO "; + } + if (secretNum.get(2) == guess.get(0)) { + response += "PICO "; + } + // Correct digits in right place? + for (int i = 0; i < 3; i++) { + if (secretNum.get(i) == guess.get(i)) { + response += "FERMI "; + } + } + // Nothin' right? + if (response == "") { + response = "BAGELS"; + } + // Get rid of any space that might now be at the end + response = response.trim(); + // If correct, change state + if (response.equals(CORRECT)) { + state = GameState.WON; + } else { + // If not, increment guess counter and check for game over + guessNum++; + if (guessNum > MAX_GUESSES) { + state = GameState.LOST; + } + } + return response; + } + +} \ No newline at end of file diff --git a/05 Bagels/java/Bagels.java b/05 Bagels/java/Bagels.java new file mode 100644 index 00000000..c5c0d71c --- /dev/null +++ b/05 Bagels/java/Bagels.java @@ -0,0 +1,129 @@ +/****************************************************************************** +* +* Bagels +* +* From: BASIC Computer Games (1978) +* Edited by David H. Ahl +* +* "In this game, the computer picks a 3-digit secret number using +* the digits 0 to 9 and you attempt to guess what it is. You are +* allowed up to twenty guesses. No digit is repeated. After +* each guess the computer will give you clues about your guess +* as follows: +* +* PICO One digit is correct, but in the wrong place +* FERMI One digit is in the correct place +* BAGELS No digit is correct +* +* "You will learn to draw inferences from the clues and, with +* practice, you'll learn to improve your score. There are several +* good strategies for playing Bagels. After you have found a good +* strategy, see if you can improve it. Or try a different strategy +* altogether and see if it is any better. While the program allows +* up to twenty guesses, if you use a good strategy it should not +* take more than eight guesses to get any number. +* +* "The original authors of this program are D. Resek and P. Rowe of +* the Lawrence Hall of Science, Berkeley, California." +* +* Java port by Jeff Jetton, 2020, based on an earlier Python port +* +******************************************************************************/ + +import java.util.Scanner; + +public class Bagels { + + public static void main(String[] args) { + + int gamesWon = 0; + + // Intro text + System.out.println("\n\n Bagels"); + System.out.println("Creative Computing Morristown, New Jersey"); + System.out.println("\n\n"); + System.out.print("Would you like the rules (Yes or No)? "); + + // Need instructions? + Scanner scan = new Scanner(System.in); + String s = scan.nextLine(); + if (s.length() == 0 || s.toUpperCase().charAt(0) != 'N') { + System.out.println(); + BagelInstructions.printInstructions(); + } + + // Loop for playing multiple games + boolean stillPlaying = true; + while(stillPlaying) { + + // Set up a new game + BagelGame game = new BagelGame(); + System.out.println("\nO.K. I have a number in mind."); + + // Loop guess and responsses until game is over + while (!game.isOver()) { + String guess = getValidGuess(game); + String response = game.makeGuess(guess); + // Don't print a response if the game is won + if (!game.isWon()) { + System.out.println(response); + } + } + + // Game is over. But did we win or lose? + if (game.isWon()) { + System.out.println("You got it!!!\n"); + gamesWon++; + } else { + System.out.println("Oh well"); + System.out.print("That's " + BagelGame.MAX_GUESSES + " guesses. "); + System.out.println("My number was " + game.getSecretAsString()); + } + + stillPlaying = getReplayResponse(); + } + + // Print goodbye message + if (gamesWon > 0) { + System.out.println("\nA " + gamesWon + " point Bagels buff!!"); + } + System.out.println("Hope you had fun. Bye.\n"); + } + + private static String getValidGuess(BagelGame game) { + // Keep asking for a guess until valid + Scanner scan = new Scanner(System.in); + boolean valid = false; + String guess = ""; + String error; + + while (!valid) { + System.out.print("Guess # " + game.getGuessNum() + " ? "); + guess = scan.nextLine().trim(); + error = game.validateGuess(guess); + if (error == "") { + valid = true; + } else { + System.out.println(error); + } + } + return guess; + } + + private static boolean getReplayResponse() { + // keep asking for response until valid + Scanner scan = new Scanner(System.in); + // Keep looping until a non-zero-length string is entered + while (true) { + System.out.print("Play again (Yes or No)? "); + String response = scan.nextLine().trim(); + if (response.length() > 0) { + return response.toUpperCase().charAt(0) == 'Y'; + } + } + } + +} + + + From 2ddf1b151d443fc0ab1e28838ab16858c41f1751 Mon Sep 17 00:00:00 2001 From: Jeff Jetton Date: Tue, 16 Feb 2021 07:08:52 -0600 Subject: [PATCH 5/8] Moved instructions out of separate class and into main Bagels.java --- 05 Bagels/java/Bagels.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/05 Bagels/java/Bagels.java b/05 Bagels/java/Bagels.java index c5c0d71c..435b5644 100644 --- a/05 Bagels/java/Bagels.java +++ b/05 Bagels/java/Bagels.java @@ -49,7 +49,11 @@ public class Bagels { String s = scan.nextLine(); if (s.length() == 0 || s.toUpperCase().charAt(0) != 'N') { System.out.println(); - BagelInstructions.printInstructions(); + System.out.println("I am thinking of a three-digit number. Try to guess"); + System.out.println("my number and I will give you clues as follows:"); + System.out.println(" PICO - One digit correct but in the wrong position"); + System.out.println(" FERMI - One digit correct and in the right position"); + System.out.println(" BAGELS - No digits correct"); } // Loop for playing multiple games From 66817de80f585a40f5dcb4e106ab4c1a510c78c2 Mon Sep 17 00:00:00 2001 From: Jeff Jetton Date: Tue, 16 Feb 2021 07:12:04 -0600 Subject: [PATCH 6/8] Update comments --- 05 Bagels/java/BagelGame.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/05 Bagels/java/BagelGame.java b/05 Bagels/java/BagelGame.java index 15dcf497..19a621c9 100644 --- a/05 Bagels/java/BagelGame.java +++ b/05 Bagels/java/BagelGame.java @@ -1,6 +1,10 @@ /****************************************************************************** * -* Encapsulates all the state and rules for one single game of Bagels +* Encapsulates all the state and game logic for one single game of Bagels +* +* Used by Bagels.java +* +* Jeff Jetton, 2020 * ******************************************************************************/ From c49699ff5dce6eda459ed0040a2d110bb8a45186 Mon Sep 17 00:00:00 2001 From: Alvaro Frias Garay Date: Tue, 16 Feb 2021 15:02:35 -0300 Subject: [PATCH 7/8] Added Guess game made in Python --- 41 Guess/python/guess.py | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 41 Guess/python/guess.py diff --git a/41 Guess/python/guess.py b/41 Guess/python/guess.py new file mode 100644 index 00000000..a0886271 --- /dev/null +++ b/41 Guess/python/guess.py @@ -0,0 +1,68 @@ +from math import log +from random import random + + +def insert_whitespaces(): + print("\n\n\n\n\n") + + +def limit_set(): + print(" Guess") + print("Creative Computing Morristown, New Jersey") + print("\n\n\n") + print("This is a number guessing game. I'll think") + print("of a number between 1 and any limit you want.\n") + print("Then you have to guess what it is\n") + print("What limit do you want?") + + limit = int(input()) + + while limit <= 0: + print("Please insert a number greater or equal to 1") + limit = int(input()) + + # limit_goal = Number of digits "limit" in binary has + limit_goal = int((log(limit) / log(2)) + 1) + + return limit, limit_goal + + +limit, limit_goal = limit_set() +while True: + guess_count = 1 + still_guessing = True + won = False + my_guess = int(limit * random() + 1) + + print("I'm thinking of a number between 1 and {}".format(limit)) + print("Now you try to guess what it is.") + + while still_guessing: + n = int(input()) + + if n < 0: + break + + insert_whitespaces() + if n < my_guess: + print("Too low. Try a bigger answer") + guess_count += 1 + elif n > my_guess: + print("Too high. Try a smaller answer") + guess_count += 1 + else: + print("That's it! You got it in {} tries".format(guess_count)) + won = True + still_guessing = False + + if won: + if guess_count < limit_goal: + print("Very good.") + elif guess_count == limit_goal: + print("Good.") + else: + print("You should have been able to get it in only {}".format(limit_goal)) + insert_whitespaces() + else: + insert_whitespaces() + limit, limit_goal = limit_set() From b359d11fa161beda59c88ab18a68b91719d12f53 Mon Sep 17 00:00:00 2001 From: Alvaro Frias Garay Date: Tue, 16 Feb 2021 15:36:01 -0300 Subject: [PATCH 8/8] Added comments --- 41 Guess/python/guess.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/41 Guess/python/guess.py b/41 Guess/python/guess.py index a0886271..98cde9b7 100644 --- a/41 Guess/python/guess.py +++ b/41 Guess/python/guess.py @@ -1,3 +1,31 @@ +######################################################## +# +# Guess +# +# From: Basic Computer Games (1978) +# +# "In program Guess, the computer chooses a random +# integer between 0 and any limit and any limit you +# set. You must then try to guess the number the +# computer has choosen using the clues provideed by +# the computer. +# You should be able to guess the number in one less +# than the number of digits needed to represent the +# number in binary notation - i.e. in base 2. This ought +# to give you a clue as to the optimum search technique. +# Guess converted from the original program in FOCAL +# which appeared in the book "Computers in the Classroom" +# by Walt Koetke of Lexington High School, Lexington, +# Massaschusetts. +# +######################################################## + +# Altough the introduction says that the computer chooses +# a number between 0 and any limit, it actually chooses +# a number between 1 and any limit. This due to the fact that +# for computing the number of digits the limit has in binary +# representation, it has to use log. + from math import log from random import random