Article 21693 of comp.sys.amiga.programmer:
Path: leela!orstcs!rutgers!cbmvax!cbmehq!cbmger!peterk
From: peterk@cbmger.de.so.commodore.com (Dr Peter Kittel Germany)
Newsgroups: comp.sys.amiga.programmer
Subject: Re: Random No.s in AmigaDOS ??
Message-ID: <9799@cbmger.de.so.commodore.com>
Date: 12 Oct 92 17:17:30 GMT
References: <1992Oct12.093044.3346@lugb.latrobe.edu.au>
Reply-To: peterk@cbmger.de.so.commodore.com (Dr Peter Kittel Germany)
Organization: Commodore Germany
Lines: 53

In article <1992Oct12.093044.3346@lugb.latrobe.edu.au> csccm@luxury.latrobe.edu.au (Chris Miles!!) writes:
>
>Can anyone tell me how you make random numbers in AmigaDOS ??
>I want to write a small script file that does different things randomly,
>so how do I get this random number??!

Well, incidentally we were just talking about how to further enhance the next
generation of AmigaDOS manuals, and one idea was to provide more examples
for AmigaDOS scripts. One of my proposals (of which I can't swear whether
it will make it anytime into that manual) is the following. It just takes
the Seconds value of the Date output. If you don't call this too fast in
series, you can get at least an "idea" of a random number (:-).
Cited:

The next script is a demonstration how you can extract an info from
the middle of an output line and process it, all with the means of
script commands.

Example 12, name RND:
      ; generate a random number
      ; take the result of Date as input
      date  >ram:zuf1
      ; generate a second script (don't care here for multitasking and <$$>)
      echo  >ram:zuf2 ".key z1,z2,z3"
      ; take only last 2 characters of 3rd argument (z3)
      echo >>ram:zuf2 "echo >env:zuf3 *"<z3>*" len=2"
      ; generate a third script, first line not yet completed!
      echo  >ram:zuf4 "execute ram:zuf2 " noline
      ; complete the line and the script
      ; the result of Date is presented as arguments z1,z2,z3 to zuf2,
      ; and thus can be separated into z1=weekday, z2=date, z3=time
      join   ram:zuf4 ram:zuf1 as ram:zuf5
      ; execute the script, gives the seconds value in zuf3
      execute ram:zuf5
      ; do a little arithmetics (divide by 2) to the seconds value
      eval <env:zuf3 >nil: value2=2 op=/ to=env:zuf6 ?
      ; show a random value between 0 and 29
      type env:zuf6
      ; clean up
      delete ram:zuf1 ram:zuf2 env:zuf3 ram:zuf4 ram:zuf5 env:zuf6 quiet

Usage: RND
When you use this as a macro to call from (or include into) another
script, leave off the last two command lines and work with the
environment variable zuf6. Don't forget to clean up later! You also
may change (or delete) the Eval command that can scale your value.

(Remark: The variable name "zuf" stems for the german word "Zufall"
for random event.)

-- 
Best regards, Dr. Peter Kittel  // E-Mail to \\  Only my personal opinions...
Commodore Frankfurt, Germany  \X/ {uunet|pyramid|rutgers}!cbmvax!cbmger!peterk



Article 21698 of comp.sys.amiga.programmer:
Path: leela!orstcs!ogicse!uwm.edu!rutgers!cbmvax!chrisg
From: chrisg@cbmvax.commodore.com (Chris Green)
Newsgroups: comp.sys.amiga.programmer
Subject: Re: Random No.s in AmigaDOS ??
Message-ID: <35821@cbmvax.commodore.com>
Date: 13 Oct 92 12:43:05 GMT
Article-I.D.: cbmvax.35821
References: <1992Oct12.093044.3346@lugb.latrobe.edu.au>
Reply-To: chrisg@cbmvax.commodore.com (Chris Green)
Organization: Commodore, West Chester, PA
Lines: 18

In article <1992Oct12.093044.3346@lugb.latrobe.edu.au> csccm@luxury.latrobe.edu.au (Chris Miles!!) writes:
>
>Can anyone tell me how you make random numbers in AmigaDOS ??
>I want to write a small script file that does different things randomly,
>so how do I get this random number??!
>
	set myvar `rx "say bitand(c2d(import('00df f006'x,4)),255)`

	This reads the beam position from the custom chips. Not normally
a good random number source, but perfectly adequate for a shell script.
-- 
*-------------------------------------------*---------------------------*
|Chris Green - Graphics Software Engineer   - chrisg@commodore.COM      f
|                  Commodore-Amiga          - uunet!cbmvax!chrisg       n
|My opinions are my own, and do not         - icantforgettheimpression  o
|necessarily represent those of my employer.- youmadeyouleftaholeinthe  r
|"A screaming comes across the sky..."      - backofmyhead              d
*-------------------------------------------*---------------------------*



Article 21958 of comp.sys.amiga.programmer:
Path: leela!orstcs!ogicse!hp-cv!sdd.hp.com!zaphod.mps.ohio-state.edu!wupost!uunet!decwrl!contessa!mwm
From: mwm@contessa.palo-alto.ca.us (Mike Meyer)
Newsgroups: comp.sys.amiga.programmer
Subject: Re: Random No.s in AmigaDOS ??
Message-ID: <mwm.2bdj@contessa.palo-alto.ca.us>
Date: 20 Oct 92 07:00:15 GMT
Article-I.D.: contessa.mwm.2bdj
References: <1992Oct12.093044.3346@lugb.latrobe.edu.au> <35821@cbmvax.commodore.com>
Distribution: world
Organization: Missionaria Phonibalonica
Lines: 22
X-NewsSoftware: Amiga Yarn 3.4, 1992/08/12 15:49:52

In <35821@cbmvax.commodore.com>, chrisg@cbmvax.commodore.com (Chris Green) wrote:
> In article <1992Oct12.093044.3346@lugb.latrobe.edu.au> csccm@luxury.latrobe.edu.au (Chris Miles!!) writes:
> >
> >Can anyone tell me how you make random numbers in AmigaDOS ??
> >I want to write a small script file that does different things randomly,
> >so how do I get this random number??!
> >
> 	set myvar `rx "say bitand(c2d(import('00df f006'x,4)),255)`
> 
> 	This reads the beam position from the custom chips. Not normally
> a good random number source, but perfectly adequate for a shell script.

If you're going to use Rexx, why not use the random number generator
that comes with it? That allows you to use the multi-argument version
to set min and max:

set myvar `rx "say random($low, $high, time('S'))"`	; untested

You might want to use the beam counter instead of the seconds hand,
but it probably doesn't make much difference in a script.

	<mike
