MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Creating a Random Function to Select an Irrational

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102294] Re: Creating a Random Function to Select an Irrational
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Tue, 4 Aug 2009 04:29:07 -0400 (EDT)

On 8/3/09 at 5:45 AM, brtubb at pdmusic.org (BenT) wrote:

>Although I am not interested in cryptograpy or statistic
>probabilities for which "random" numbers are typically used, if not
>"relied" on, my biggest concern, that your use of WorkingPrecision
>partly addresses, is the prevention of repeating digits within the
>"random" value which would imply some sort of "rationality" to the
>number.

Repeating digits do not necessarily imply a rational number. For
example, a number constructed as follows:

0.11010010010001

That is 1 separated by an increasing number of zeros, certainly
has repeating digits (0) but is definitely not rational.

As Andrezej pointed out, every number in any finite precision
that is not an integer that can be represented by Mathematica
can be viewed as the first n digits of a rational or irrational
number. The only numbers Mathematica can represent that are
certain to be irrational are those involving exact expressions
such as Sqrt[2].

>Another "definition" which you implied, could also be used, that
>hadn't occurred to me <g> and more than provides me with what I
>want; besides which the "probability" of their being a repeating
>sequence of numbers is also virtually zero -- and this "method" is
>much easier to implement, and runs faster <g>.

>rnd[digits_Integer,base_Integer]:=
>Module[{dvs},
>For[dvs = "";x = 1,x < digits, x++,
>dvs = dvs <> ToString[RandomInteger[base-1]] <> ","];
>dvs = dvs <> ToString[RandomInteger[base-1]]]

The same result can be had more simply by doing

RandomInteger[{0,base-1}, digits]

And this will execute faster than the For loop you use in your
code above. It does differ from your code in that the output is
a list of numbers rather than a list of strings. If you do need
strings, they can easily be obtained by doing

ToString/@RandomInteger[{0,base-1}, digits]



  • Prev by Date: Re: error with Sum and Infinity
  • Next by Date: Re: Multiplication of matrices
  • Previous by thread: Re: Re: Creating a Random Function to Select an Irrational
  • Next by thread: Assume and $Assumptions and Results