Random Number with Seed value
Author Message
Random Number with Seed value

I would like a Random number generator that I can give a seed value to so
that I can recreate and test routines using the random function.
Is there any way to get the builtin Random number function to do this?
If not does anybody have anything to do this?

Thank you - Ed Campbell
Using C5b

Mon, 12 Apr 2004 08:37:23 GMT
Random Number with Seed value
Ed,
Check random() in the help!
Dave Beggs

Quote:
> I would like a Random number generator that I can give a seed value to so
> that I can recreate and test routines using the random function.
> Is there any way to get the builtin Random number function to do this?
> If not does anybody have anything to do this?

> Thank you - Ed Campbell
> Using C5b

Mon, 12 Apr 2004 09:53:07 GMT
Random Number with Seed value
I to have not been able to seed the Clarion Random number BUT the code for a
simple integer random number generator is pretty easy -- BUT you must
implement the code EXACLTLY as shown.

This code derives for Texas Instrument Designer's Notebook "Random Number
Generation on a TMS320C5X", contributed by Eric Wilbur. Which, for our
purposes, simply means a 32 bit fixed point processor.

!-------------------

RandomValue    LONG(SeedValue)    ! A global variable

CustomRandom    FUNCTION
CODE
RandomValue *= 2147483621    ! DO NOT change these 2 lines in ANY WAY
and,
RandomValue += 907633386    ! DO NOT make any other changes to the
contents of RandomValue
Return(RandomValue)

! Since the random result is a 32bit signed value, you will have to perform
the necessary scaling for your application.
! BUT, do not make any changes directly to RandomValue's value!
! Also see below ...
!-------------------

WARNING! The exact numbers shown have A LOT of statistics behind them so you
must use these exact values. Also DO NOT combine the 2 lines into one line
or change RandomValue to anything other than a long (the constants are
specific to the "width" of the variable used -- these constants are
specifically for a 32 bit signed integer)! The Pseudo-Random value is
created by the overflow and roundoff calculations of each line.

Go to www.ti.com and look for this paper, and it's associated equations, to
calculate the appropriate constants for other variable sizes.

Hope this helps!

Charles

Mon, 12 Apr 2004 10:13:17 GMT
Random Number with Seed value
Hi Ed,

Quote:
>I would like a Random number generator that I can give a seed value to so
>that I can recreate and test routines using the random function.
>Is there any way to get the builtin Random number function to do this?
>If not does anybody have anything to do this?

I don't think there is any way to do this in Clarion directly, but
what I have done many times is to use a queue or a file.  Load it up
with random numbers and then use the queue/file over and over again
for testing.

RQ   Queue
RN     Long
End
I    Equate(100000)
Code
Loop I Times
RQ.RN = Random(1,I)
Add(RQ)
End

Something like that...

Best regards,

Arnr Baldvinsson
Icetips Software
San Antonio, Texas, USA
www.icetips.com

ICQ:  113314380

Mon, 12 Apr 2004 22:39:31 GMT
Random Number with Seed value
Here's an example of a Procedure that I use to generate seeded random
numbers. It uses the internal C _srand and _rand procedures that deal
with two byte integers. I call _rand twice and combine the results.

Note: When called from threaded procedures, the seed value is not
maintained.

PROGRAM

MAP
SRandom    PROCEDURE(<USHORT seed>),LONG,PROC ! optional return
MODULE('C API')
Rand         PROCEDURE(),LONG,NAME('_rand')
Srand        PROCEDURE(USHORT seed),NAME('_srand')
END !module
END

CODE
SRandom(12345)    ! set the seed value
LOOP j# = 1 TO 5
x# = SRandom()  ! get successive seeded pseudo random numbers
MESSAGE(x#,j#)
END !loop
RETURN

SRandom    PROCEDURE(<USHORT seed>) ! this does the work
Result       LONG,AUTO
OverGrp      GROUP,OVER(Result)
A              SHORT
B              SHORT
END !group
CODE
IF NOT OMITTED(1)
SRAND(seed)        ! set the seed value
END !if
OverGrp.A = Rand()
OverGrp.B = Rand()
RETURN(Result)

I hope this makes sense...

Quote:

> I would like a Random number generator that I can give a seed value to so
> that I can recreate and test routines using the random function.
> Is there any way to get the builtin Random number function to do this?
> If not does anybody have anything to do this?

> Thank you - Ed Campbell
> Using C5b

--
Randy Goodhew
---[ eq ]---

Mon, 12 Apr 2004 23:21:59 GMT
Random Number with Seed value
Excellent idea, Arnr.

-Ray.

Quote:
> Hi Ed,

> >I would like a Random number generator that I can give a seed value to so
> >that I can recreate and test routines using the random function.
> >Is there any way to get the builtin Random number function to do this?
> >If not does anybody have anything to do this?

> I don't think there is any way to do this in Clarion directly, but
> what I have done many times is to use a queue or a file.  Load it up
> with random numbers and then use the queue/file over and over again
> for testing.

> RQ   Queue
> RN     Long
>      End
> I    Equate(100000)
>  Code
>  Loop I Times
>   RQ.RN = Random(1,I)
>   Add(RQ)
>  End

> Something like that...

> Best regards,

> Arnr Baldvinsson

Mon, 12 Apr 2004 23:23:01 GMT
Random Number with Seed value
Ed -

Not 100% sure, but I believe you can use rand() and srand():

program

map
Module('')
Rand(),short,name('_rand')
SRand(ushort),name('_srand')
end
end

R    Short
S    String(200)

Code

SRand(100)
Loop 20 times
R = Rand()
S = Clip(S) & ', ' & R
end
Message(S)

Seems to be reproducible.

Quote:
>I would like a Random number generator that I can give a seed value to so
>that I can recreate and test routines using the random function.
>Is there any way to get the builtin Random number function to do this?
>If not does anybody have anything to do this?

Jeff Slarve
http://www.jssoftware.com

Tue, 13 Apr 2004 00:07:58 GMT
Random Number with Seed value
Ed,

I have used RANDOM() to generate passwords.
I have generated 100.000 passwords in *one loop*
without getting a single duplicate.

--

Best regards,
Maarten
CDD3.1, C5EEb - ABC & C5.5.04EE
Certainly Clarion Developer

Tue, 13 Apr 2004 03:43:26 GMT
Random Number with Seed value
I forgot to clearly mention that anytime you want to SEED the code I
provided just set "RandomValue = SeedValue". I tried to imply this using the
init value in the LONG def.

Tue, 13 Apr 2004 05:07:12 GMT
Random Number with Seed value
Dave,

I did. I have used random in the past but never needed to reproduce my
results. Random() only allows you a low and high range but no start
position. Am I missing something?

Ed

Quote:
> Ed,
> Check random() in the help!
> Dave Beggs

> > I would like a Random number generator that I can give a seed value to
so
> > that I can recreate and test routines using the random function.
> > Is there any way to get the builtin Random number function to do this?
> > If not does anybody have anything to do this?

> > Thank you - Ed Campbell
> > Using C5b

Tue, 13 Apr 2004 06:24:50 GMT
Random Number with Seed value
Jeff,

Did you try this? I did and I got different results. Am I doing something
wrong (seems pretty staightforward)?
This is my code.

srand(100)
loop i# = 1 to 10
stop(rand())
End

stop('Try again')

srand(100)
loop i# = 1 to 10
stop(rand())
End

Second time thru the numbers are different. Any thoughts?

Thanks - Ed

Quote:
> Ed -

> Not 100% sure, but I believe you can use rand() and srand():

>  program

>   map
>    Module('')
>       Rand(),short,name('_rand')
>       SRand(ushort),name('_srand')
>    end
>   end

> R    Short
> S    String(200)

>   Code

>   SRand(100)
>   Loop 20 times
>     R = Rand()
>     S = Clip(S) & ', ' & R
>   end
>   Message(S)

> Seems to be reproducible.

> >I would like a Random number generator that I can give a seed value to so
> >that I can recreate and test routines using the random function.
> >Is there any way to get the builtin Random number function to do this?
> >If not does anybody have anything to do this?

> Jeff Slarve
> http://www.jssoftware.com

Tue, 13 Apr 2004 06:26:41 GMT
Random Number with Seed value
Ed,
I haven't used it for a while.  I did some stochastic modelling in Clarion
2.1 and compared the random function in CPD 2.1 and Excel at the time.  One
produced a "normal" type distribution between the extremes and one produced
a "flat" type distribution.  If you print out 500000 random numbers then do
a frequency distribution histogram you can see what Clarion 5 does.  In
either case, it depends what you are using it for.  If you just want a
"Yes/No" random number then something like  if random(1,100) > 50 = true
will do no matter the distribution type.
Cheers!
Dave Beggs

Quote:
> Dave,

> I did. I have used random in the past but never needed to reproduce my
> results. Random() only allows you a low and high range but no start
> position. Am I missing something?

> Ed

> > Ed,
> > Check random() in the help!
> > Dave Beggs

> > > I would like a Random number generator that I can give a seed value to
> so
> > > that I can recreate and test routines using the random function.
> > > Is there any way to get the builtin Random number function to do this?
> > > If not does anybody have anything to do this?

> > > Thank you - Ed Campbell
> > > Using C5b

Tue, 13 Apr 2004 06:45:54 GMT
Random Number with Seed value
Ed -

No. Sorry.

Quote:
>Second time thru the numbers are different. Any thoughts?

Jeff Slarve
http://www.jssoftware.com

Tue, 13 Apr 2004 16:29:20 GMT

 Page 1 of 1 [ 13 post ]

Relevant Pages

Powered by phpBB® Forum Software