• 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 17:45:49 -0400

On 8/14/07, Jakob Peterhänsel <email@hidden> wrote:
> Hi All,
>
> Anyone have a method to get a random number in AS?
>
> Native or via do shell script ?

For a pseudo-random number with only 15 bits of precision, you can use
the shell's $RANDOM variable:

set randomNumber to do shell script "echo $RANDOM";

which will get you a random integer uniformly distributed between 0
and 32767, inclusive.  You can then take the remainder with respect to
some integer (if you're looking to simulate a dice roll or similar) or
divide by 32768 to get a float in the [0,1) range.


--
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: "Mark J. Reed" <email@hidden>
References: 
 >Get Random number? (From: Jakob Peterhänsel <email@hidden>)

  • Prev by Date: Get Random number?
  • Next by Date: Re: Get Random number?
  • Previous by thread: Get Random number?
  • Next by thread: Re: Get Random number?
  • Index(es):
    • Date
    • Thread