Item -1 of a list

Hmm. Okay. Getting a random integer within a given range is straightforward. (Actually, that's a lie; the process for generating one and the mathematics to prove that the ones you generate really are uniformly distributed are quite complicated. But from the user's point of view, it's clear what it means to want/have a random choice from a range of integer values.

Fixed-point fractional random numbers (e.g., to two decimal places), as you understand, is essentially the same problem as random integers, but scaled.

But what about random numbers on a truly continuous range? You can imagine various physical processes, e.g., throw darts at a linear dart board. But how do you do it computationally?

Since 64-bit floating point values are limited to 15 or 16 decimal significant digits, one practical solution is this:


(20 rather than 16 just to be sure to avoid nonrandomness in the low-order bit. But if all the random digits are nines, the result will be rounded to 1.0 by the decimal input algorithm, alas.)

But there are multiword floating point packages, so you can get floating point values to any arbitrary precision, so in principle this is a bad approach even in digital algorithm terms, and no matter what precision you use, it won't give you truly random real values. For that you have to do something non-digital. The diode approach is a textbook example.

Does that help?

ah, thanks. That makes much more sense.

I should add that it's far from obvious (and I'm not even sure it's true) that the values produced by my procedure will be uniformly distributed after rounding. For all I know, some floating point value might be the rounded version of 1000 20-digit numbers, and then next floating value up might be the rounded version of only 999 20-digit numbers.

well, after a bit of coding, and debugging, I found out a way to use the pick random block in it. This way there won't be list length limits, and with huge numbers, it'll be much much quicker.

Wait, (num1 x 10) / (in x 10) should be the same as num1/in.

like this?

Same for the second input to random, and there's a similar "/ 10" and "x 10" undoing each other outside the PICK RANDOM block. C'mon, you don't need me to do arithmetic for you! :~P

ah, ok.

:white_check_mark: :~)

Here's a way to generate as many decimal places as memory and patience permits

image

It took a few seconds to generate 1 out of a google * google possible numbers between 0 and 1. I.e. 10,000 random digits.

The result is displayed as a fraction but it is a number between 0 and 1. [0, 1) since it will never generate 1.

Note also that it would be easy to change to use any other base - e.g. binary so it doubles and then adds either 0 or 1 each time.

I am mystified about the following

image

A problem with the Bignum library?

Here's the project (requires the bignum/rational library):

The project is

(without "Can" at the end, sorry about that)

And about this ?

Be wary of the limits of floating point numbers. I'm not sure how many zeros you used but note:

image

while

whatsapp script pic (2)

If you used too few zeros then it might report a number very slightly out of the range. Too many zeros and floating point arithmetic fails you.

See Number.EPSILON

@djdolphin (Probably because of hyperblocks?)

Funny how our fingers develop habits in a time of monopoly capitalism. :~)

I believe it's related to this Bignums/random need rounding

You caught me right when spring break started, so I'll fix the issue soon.

Oh, right, I forgot all about that thread.

You can't use Math.random() for random bignums, because floats only have 15½ significant digits. I guess the right thing is to generate them digit by digit, generating lots more digits than the user's desired range really needs and then scaling in exact integer arithmetic.

Random exact rationals may just be two random bignums as numerator and denominator, but I'm not sure, because common factors may make some results more frequent than others. Some mathematician will have to figure that out...

Random complex numbers can't be made with the PICK RANDOM block, because complex numbers aren't ordered, so the idea of specifying a range won't work. Instead the user will have to pick two random reals/bignums/rationals as desired and then turn them into a complex number.

Thanks!

Yes. I meant googol. Embarrassing...

So, here's Wikipedia on random numbers. It's about as readable as all the other Wikipedia math articles, but it does have one piece of good news:

GNU Scientific Library has a section entitled "Random Number Distributions" with routines for sampling under more than twenty different distributions.

The GNU documentation is often readable, or maybe you can just steal code from them, supposing it comes in arbitrary precision.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.