Can AppleScript generate a random number?

I need to do a small test script that generates a random number. If AS cannot do this I will have to write an app in RB or some other programming language. I am hoping to get away with a simple script.

If AS can generate a random number, what is the command?

Jmax

See the ‘random number’ command in Standard Additions. Also of interest: http://www.applemods.com/getMod.php?script_ID=44. (Neither is truly random, but good enough for most purposes.)

There is also such a thing as an obnoxious signature. [hint]

random number

returns a real number between 0 and 1

random number from 1 to 1000

returns a real number between 1 and 1000

random number from 1 to 1000 with seed 29238239

returns a random number from 1 to 1000 using the specified seed value, useful for repeating the random sequence - sounds like an oxymoron, I know :slight_smile:

I got the program written. I was not sure that I was going to be able to do it all in AS. But I am quite happy with the result. I am thinking of trying out FaceSpan to put a face on it. It was only to demonstrate what AS could do for the people I work for.

I want to get other people doing some scripting to increase our productivity. The ‘boss’ thinks that spending time programming is wasteful and could actually be spent better on actual production. I have explained again and again that if we could spend a few hours on a script that ends up saving … well, one scripts saved over 2000 man hours … that this would ‘sometimes’ be more productive, and therefore more profitable. The aforementioned script took 5 hours to write and debug. And that was just because it was one of my first.

Ah, well, such is life when working for someone else.

Thanks for the help.

Note to HAS: I don’t understand why you find my sig to be obnoxious, but I guess this isn’t the place for that discussion. Feel free to email me if you care to discuss this.

A friend named Cian helped me with a script to generate random Lotto numbers a while back. Maybe you can incorporate the methods to suit your needs…


global vlu
global rcrd
set vlu to 0
set numbr to 0
set cownt to 0

repeat
	set rcrd to {55, 55, 55, 55, 55, 55}
	repeat with numbr from 1 to 6
		randm()
		set item numbr of rcrd to vlu
	end repeat
	display dialog ¬
		" Here Are Your Lottery Numbers: " & return & "
		" & item 1 of rcrd & " ,  " & item 2 of rcrd & " ,  " & item 3 of rcrd & " ,  " & item 4 of rcrd & " ,  " & item 5 of rcrd & " ,  and  " & item 6 of rcrd buttons {"End", "Try Again"} default button 2
	if button returned of result is "End" then exit repeat
end repeat

------generates and checks numbers against those already generated for uniqueness

on randm()
	set answr to random number from 1 to 55
	if answr ? item 1 of rcrd and answr ? item 2 of rcrd and answr ? item 3 of rcrd and answr ? item 4 of rcrd and answr ? item 5 of rcrd and answr ? item 6 of rcrd then
		set vlu to answr
		return
	end if
	randm()
end randm