• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Get Random number?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Get Random number?


  • Subject: Re: Get Random number?
  • From: "Mark J. Reed" <email@hidden>
  • Date: Tue, 14 Aug 2007 18:02:43 -0400

On 8/14/07, Daniel Brieck Jr. <email@hidden> wrote:
> One AppleScript native method is to use the command
>
> random number

Thank you, didn't know about that.  I see it's part of the Standard
Additions osax.

> It will return a number between 0 and 1 by default,  there appears to
> be a way to seed is so that it goes between two non-negative integers

Two different things.  Seeding a pseudo-random number generator
provides control over the sequence of numbers it returns - a given
seed will always cause the same numbers to come back out, even though
the numbers will appear to be distributed randomly.    (You can do
this in the shell, too, by assignment: RANDOM=seedvalue)

You can also convince "random number" to return an integer within a range.

> according to this book "AppleScript The Definitive Guide" , but I
> can't seem to find out how to do that.

According to this (which I found by Googling "applescript random number"):

http://docs.info.apple.com/article.html?path=AppleScript/2.1/en/as211.html

The full form is this:

random number from minValue to maxValue with seed X

You can leave off "with seed X" to continue the sequence from wherever
it happens to be instead of re-seeding.

You can leave off "from minValue to" in which case minValue is 0.

You can leave off "maxValue" in which case maxValue is 1.

If either minValue or maxValue is a real number, or if you leave both
off, the result is real; otherwise the result is an integer So:

random number from 1 to 6

will simulate rolling a die.
--
Mark J. Reed <email@hidden>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Get Random number?
      • From: Arnaud Nicolet <email@hidden>
References: 
 >Get Random number? (From: Jakob Peterhänsel <email@hidden>)
 >Re: Get Random number? (From: "Daniel Brieck Jr." <email@hidden>)

  • Prev by Date: Re: Get Random number?
  • Next by Date: Trouble getting AppleScript to execute an Automator app multiple times
  • Previous by thread: Re: Get Random number?
  • Next by thread: Re: Get Random number?
  • Index(es):
    • Date
    • Thread