[{"element_type":"image_url","content":"https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Leonard_Nimoy_as_Spock_1967.jpg/220px-Leonard_Nimoy_as_Spock_1967.jpg","metadata":{"alt":"Mr","caption":"Fascinating. Is this logical? "}},{"element_type":"text","content":"\n        \u003cp\u003e\u0026nbsp;\u003c/p\u003e\n\u003cp\u003eI love using the random library - it's a simple way to introduce variety into simple programs and here's one example, what I call \"Spock on a Chip.\" Here's a link to the \u003ca title=\"Spock on a Chip\" href=\"https://github.com/mrklingon/SpockOnAChip/\" target=\"_blank\"\u003erepository.\u003c/a\u003e\u003c/p\u003e\n\u003cp\u003eCopy the files to a NeoTrinkey, changing \"spock.py\" to \"code.py\" - when it runs, it occasionally blinks lights, but when you touch one of the pads, it will blink and then pick a random quote out of the \"spock\" file and print it. If REPL=True, you'll need to be in an editor like mu to see the text. IF you change REPL to be \u003cstrong\u003eFalse\u003c/strong\u003e, then it will use HID support to send the text as if typed on a keyboard! Just the way to jazz up your email! Edit the \"spock\" file to add your own favorite quotes from everyone's favorite Vulcan.\u003c/p\u003e\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eWhat's going on?\u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003eThere are two functions that are used to deliver the quotes. len_file(filename),\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003edef file_len(filename):\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp; \u0026nbsp; with open(filename) as f:\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp; for i, _ in enumerate(f):\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp; pass\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp; \u0026nbsp; return i + 1\u003c/code\u003e\u003c/p\u003e\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\n\u003cp\u003eand wisdom(file_name).\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003edef wisdom(filename):\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003e\u0026nbsp; \u0026nbsp; qs = open(filename)\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp; \u0026nbsp; for i in range(random.randrange(file_len(filename))+1):\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp; quote = qs.readline()\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp; quote = quote.rstrip()\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp; \u0026nbsp; cmpthink()\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp; \u0026nbsp; qs.close()\u003c/code\u003e\u003cbr\u003e\u003ccode\u003e\u0026nbsp; \u0026nbsp; return (quote.rstrip())\u003c/code\u003e\u003c/p\u003e\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\n\u003cp\u003eGive a file name, wisdom() calls len_file() to determine how big the file is, then uses random.randrange() to select the text - that means you can add or subtract from the \"spock\" file without needing to update the program.\u003c/p\u003e\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\n\u003cp\u003eThe fun thing with this code is, it can be reused for other purposes. I've already used it to put together a \"story\" program that uses multiple source files (aliens, suns, planets, etc.) that can be drawn from to generate story lines. It could be used for a \u003ca title=\"Wikipedia article about Diceware\" href=\"https://en.wikipedia.org/wiki/Diceware\" target=\"_blank\"\u003ediceware\u003c/a\u003e style passphrase generator. And, of course, it doesn't have to be Spock on a chip - you can fill the \"spock\" file with any quotes you choose.\u003c/p\u003e\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\n      ","metadata":{}}]