Posts

Showing posts with the label random numbers

My favorite mathematical card trick

Image
I learned this card trick in the fourth grade, decades ago, before the World Wide Web existed. I have never seen it written about, and anyone to whom I have shown it has never seen it either. This is surprising given how long I've known this trick. Did a brilliant classmate (or a parent) invent it? I'd love to know the origin. This is a mathematical card trick. Meaning, there is no sleight of hand, no actual trickery, just manipulation of playing cards that gives a surprising, final result. You can find many examples of mathematical card tricks on the internet; some of them appear downright magical and quite impressive. What the audience sees Here is how this trick appears to the audience. It looks like many steps, but they are easy to remember after you've practiced the trick even once: Starting with a deck of 52 cards (no jokers), you ask a volunteer from your audience shuffle the deck. You deal out the cards into seemingly arbitrary face-up piles, handing t...

Legitimate uses of loaded dice

Image
A game master / dungeon master (DM) should never allow a player to bring 3D printed dice to a game. However, a DM could supply them to players, for certain purposes. In this article I examine the characteristics of "most fair" and "most unfair" designs of d20 dice, which I made in a CAD program and 3D printed for experiments. A fair and balanced d20 (white), a d20 biased to 20 (bronze, with the ☺ on the 20 face), and a d20 biased to 1 (purple, with the F for "fail" on the 1 face). A d20 is a twenty-sided icosahedron with faces numbered from 1 to 20. In the game Dungeons and Dragons , the d20 is ubiquitous. It determines success or failure of an action. It is the first thing rolled any time a player takes an action. The result of the d20 roll, with some modifiers added based on the player's character abilities and skills, determines whether the player's action succeeds or fails, with appropriate consequences. Advantage and disadvantage...

Simulating erosion

Image
I decided to create a procedurally-generated 3D landscape in a CAD program, and wrap it around a globe, which led me to an investigation of erosion algorithms. I include a JavaScript erosion demo at the end of this article for you to play with. As an aside, let me say that I like OpenSCAD in spite of its idiosyncrasies. Other CAD programs can do many things that OpenSCAD can't, but OpenSCAD is the only 3D modelling software I know of that makes it easy to create procedural or algorithmic parametric designs. It runs on all my computers: Windows, macOS, and Linux — and it's freeware. Its main idiosyncrasy is that it uses a declarative language that requires familiarity with functional programming , a different programming mindset in which all values are evaluated at compile-time instead of run-time, meaning that all "variables" are effectively constants. Even so, one still has conditional branching, looping, and recursive functions, so one can get stuff done. For exa...

Most probable array of D&D ability scores

Image
There's an element to the game Dungeons & Dragons that lends itself to a numerical analysis: the initial array of ability scores assigned to a character. Some background: A character in the game has scores assigned to each of six abilities (strength, dexterity, constitution, intelligence, wisdom, and charisma). The first step in creating a character is to generate an array of six numbers by rolling dice, using a method known as "4d6 drop lowest". This means, roll four six-sided dice, remove the lowest value, then add the remaining three dice together (the result ranges from 3 to 18). Do this six times to generate an array of six values, then assign these values to your character's abilities as appropriate for the character's role (fighter, cleric, wizard, etc.). The problem The question I want to answer here is: What does a "typical" array look like? More importantly, how would I know if the array I end up with is better or worse than average? ...

Random walk oscillator

Image
May 2017: This is from my other blog that's no longer online. The original comments are no longer available, but you are welcome to add more. Here's an experiment. Suppose I want to make a random walk that I can control, that doesn't wander aimlessly all over, but rather is attracted to zero. The attraction back to zero wouldn't act like a force that causes steps away from zero to become smaller in size; rather, steps toward zero are simply more probable further away from zero, regardless of the step size. I'll invent a random walk that does this. We generate random walk steps in a generalized way via some inverse cumulative distribution function (cdf), which could represent a gaussian, a black swan , binary ±1 steps, whatever. This inverse cdf, in turn, takes as an input a random probability p that's uniformly -distributed between 0 and 1. (If you want uniformly-distributed steps, the step size simply equals the input p , or a multiple of p .) We need to ...

Fake data, part 3: Bypassing the central limit theorem

Image
The black swan distribution Perturbing volatility May 2017: This is from my other blog that's no longer online. The original comments are no longer available, but you are welcome to add more. Now that I have my black swan distribution , and I verified that it fits market returns remarkably well while being mathematically tractable, I want to use it to generate artificial market data. Generating a series of closing prices is easy. Select a starting price, take the logarithm Select a mean μ and standard deviation σ of log returns ln( P 0 / P 1 ) where P 0 is the most recent price and P 1 is the previous price. Generate a uniformly-distributed random probability p between 0 and 1. Plug it into the inverse black swan distribution (using a =1.6): $$B^{-1}(p;\mu,s) = \mu - 2 s \, \sinh \left[\frac {\tanh^{-1}(1-2p)} {a} \right]$$ Add the result to a running total. Go to step 3. Repeat as often as desired. Then simply calculate the antilog or exponential of the value...

Popular posts from this blog

Syncing Office 365 Outlook to Google calendar using Power Automate

Whose hands are biggest? You may be surprised.

Elliptical-blade NACA airfoil propeller