Searching \ for 'Random number generator' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/method/math.htm?key=random
Search entire site for: 'Random number generator'.

Truncated match.
PICList Thread
'Random number generator'
1997\05\13@125131 by Antonio Almeida

flavicon
face
I need a routine that returns a random number to implement something similar
to CSDMA/CD. I need it to make a random wait time after a collision, i've
seem some routines but how do i get different seeds to inicialize the
routine ?

Thanks,
Antonio Almeida

1997\05\13@134532 by Tim Kerby

picon face
Hi

Get the seed from a timer value.  It makes rnd# generation much better.  I
had to implement it in a toy and it works really well.


Tim


At 17:17 13/05/97 +0000, you wrote:
>I need a routine that returns a random number to implement something similar
>to CSDMA/CD. I need it to make a random wait time after a collision, i've
>seem some routines but how do i get different seeds to inicialize the
>routine ?
>
>Thanks,
>Antonio Almeida
>


------------------------------------------------------------------
Personal Web Pages: http://web.ukonline.co.uk/members/tim.kerby/
PIC Site: web.ukonline.co.uk/members/tim.kerby/pic/
The PIC Pages are under construction and I am looking for projects
------------------------------------------------------------------

1997\05\13@212757 by John Payson

flavicon
face
> I need a routine that returns a random number to implement something similar
> to CSDMA/CD. I need it to make a random wait time after a collision, i've
> seem some routines but how do i get different seeds to inicialize the
> routine ?

Hmm... depending upon the number of nodes in your system and how they're
powered you /may/ have a problem.  While using a timer to seed your RNG is
a nice concept, it won't do much good if several PICs happened to choose
the same seed (as would be quite possible if all the machines were powered
on simultaneously).  If the seeds happen to match, it doesn't matter how
many times you cycle the RNG; all the "random" numbers are going to match
as well.

In many network topologies, a node's address is used to seed the
random-delay routine (or else simply sets a fixed delay duration).  Would
such an approach be feasible for you?  If every node has a unique address,
that would provide a good way of producing the "random" delays without the
"bad" cases you could get with a timer-seeded RNG.

1997\05\14@032210 by Arne Hedevang

flavicon
face
I have made a "random" routine for a CSMA/CD network in a
16C84. I used bit0-3 from TMR0, it gave me a 16 step
"random" number. With 208 uSec delay pr. step, it gave
a delay from the last collision, between 0 and 3.12 mSec. (to
that, I added 5 mSec). It works very well, due to the fact, that
all the 4 MHz x-tal on the network, are not synchronized.

mvh
Arne Hedevang
Denmark


> I need a routine that returns a random number to
implement something similar
> to CSDMA/CD. I need it to make a random wait time after
a collision, i've
> seem some routines but how do i get different seeds to
inicialize the
> routine ?

Hmm... depending upon the number of nodes in your system
and how they're
powered you /may/ have a problem.  While using a timer to
seed your RNG is
a nice concept, it won't do much good if several PICs
happened to choose
the same seed (as would be quite possible if all the
machines were powered
on simultaneously).  If the seeds happen to match, it doesn't
matter how
many times you cycle the RNG; all the "random" numbers
are going to match
as well.

In many network topologies, a node's address is used to
seed the
random-delay routine (or else simply sets a fixed delay
duration).  Would
such an approach be feasible for you?  If every node has a
unique address,
that would provide a good way of producing the "random"
delays without the
"bad" cases you could get with a timer-seeded RNG.

1997\05\14@045249 by obo (Ingenieria Fotonica)

flavicon
face
At 17:17 13/05/97 +0000, you wrote:
>I need a routine that returns a random number to implement something similar
>to CSDMA/CD. I need it to make a random wait time after a collision, i've
>seem some routines but how do i get different seeds to inicialize the
>routine ?

Hello,
I've found that performing a XOR operation with all the un-inisialized
values of the user RAM at startup (in the PIC16C84), you get a good random
seed.
 Adolfo.


-----------------------------------------------------------------------
|         Adolfo Cobo Garcia  -  UNIVERSIDAD DE CANTABRIA               |
|    E.T.S.I.I. y Telecomunicacion, Grupo de Ingenieria Fotonica        |
|        Avda. Los Castros s/n  E-39005  Santander  SPAIN               |
|  Tfno. +34-42-201539  Fax +34-42-201873  Email: spam_OUTacoboTakeThisOuTspamteisa.unican.es |
-----------------------------------------------------------------------

1997\05\14@200638 by John Payson

flavicon
face
> At 17:17 13/05/97 +0000, you wrote:
> >I need a routine that returns a random number to implement something similar
> >to CSDMA/CD. I need it to make a random wait time after a collision, i've
> >seem some routines but how do i get different seeds to inicialize the
> >routine ?
>
>  Hello,
>  I've found that performing a XOR operation with all the un-inisialized
> values of the user RAM at startup (in the PIC16C84), you get a good random
> seed.

Yes, but if two PICs happen to XOR to the same value you're sunk.  Even
using a 2-byte XOR of user RAM is no guarantee of safety; depending upon
the characteristics of the chips you may find that certain chips tend
toward the same stuff.  For a CSDMA/CD application, that would be a
killer.

1997\05\16@090839 by Antonio Almeida

flavicon
face
On Wed, 14 May 1997, John Payson wrote:

> > At 17:17 13/05/97 +0000, you wrote:
> > >I need a routine that returns a random number to implement something
similar
{Quote hidden}

I think i found a solution to make a random seed generator, at least one
to solve this problem. It's something like this:

      Vdd
       |
       -         --------         The function will work like this:
      | |       |   PIC
      | |       |                    1.  Pin R (output) = 0
       -        |                    2.  Pin R (input)
       |        |                    3.  Start counter
       +--------| R                  4.  While R == 0 increment counter
       |        |                    5.  Stop counter
     -----      |                    6.  Return counter
     -----      |
       |                  We only need to use some very cheap components
     -----                (with big tolerances) to get a fair random
                          seed generator :-).

Antonio Almeida

1997\05\16@103604 by Bob Fehrenbach

picon face
some time ago someone posted a suggestion for generating a RNG seed
using the watch dog.  Essentially, the processor was allowed to
generate a watch dog reset at power up and the timer was read when
the processor was restarted.  I haven't tried it but it sounds like
in may have merit.

--
Bob Fehrenbach    Wauwatosa, WI     .....bfehrenbKILLspamspam@spam@execpc.com

1997\05\16@120806 by Gerhard Fiedler

picon face
At 19:06 14/05/97 +0000, John Payson wrote:
>>  Hello,
>>  I've found that performing a XOR operation with all the un-inisialized
>> values of the user RAM at startup (in the PIC16C84), you get a good random
>> seed.
>
>Yes, but if two PICs happen to XOR to the same value you're sunk.  Even
>using a 2-byte XOR of user RAM is no guarantee of safety; depending upon
>the characteristics of the chips you may find that certain chips tend
>toward the same stuff.  For a CSDMA/CD application, that would be a
>killer.

I'm not familiar with all the details of what you're doing, but wouldn't it
help to include some kind of a serial number in your code (that changes
with every device), and use this, maybe together with other "randomizing"
measures? Wouldn't you need some kind of individual id anyway? So just
include it in your seed calculations, and you (almost) never get two identical.


'random number generator'
1997\09\03@172301 by Marc R Boehlen
flavicon
face
Folks

I am new to this community and would like to ask if anyone has a routine
for a 16C84 to generate random numbers?

thanks,                            marc bohlen

1997\09\03@181928 by Dave Reinagel

picon face
> Folks
>
> I am new to this community and would like to ask if anyone has a routine
> for a 16C84 to generate random numbers?
>
> thanks,                            marc bohlen
>

For a 16 bit pseudo-random number (2**16-1 states):

random          res     2;      reserve space for number
...
; on power-up, initialize the number to any non-zero value
       movlw   1;
       movwf   random+1;
...
; to get the next pseudo-random number
       clrf    temp1;          to make the next value
       movfw   random;         get high byte
       andlw   0xB4;           isolate bits for exclusive or
       movwf   temp2;
loop:   movfw   temp2;
       addwf   temp2,f;        shift temp and set Z when done
       btfsc   STATUS,C;       check if next bit is set
       incfsz  temp1,f;
       btfss   STATUS,Z;       check if temp2 is now zero
       goto    loop;
       rrf     temp1,f;        get parity of random ^ 0xB4 into C
       rlf     random+1,f;     now shift random number to the left
       rlf     random,f;
...

Now if you initialize the random number to the same seed everytime,
you will always get the same pattern of numbers out.  So you might
want to try using the value of a timer initially to seed the pseudo-
random number generator, but make sure it is not zero.

Dave Reinagel

1997\09\04@014032 by Peter Homann

picon face
Marc R Boehlen wrote:
>
> Folks
>
> I am new to this community and would like to ask if anyone has a routine
> for a 16C84 to generate random numbers?
>
> thanks,                            marc bohlen

This is a routine Dave Reinagel posted a while ago.


For a 16 bit pseudo-random number (2**16-1 states):

random          res     2;      reserve space for number
...
; on power-up, initialize the number to any non-zero value
       movlw   1;
       movwf   random+1;
...
; to get the next pseudo-random number
       clrf    temp1;          to make the next value
       movfw   random;         get high byte
       andlw   0xB4;           isolate bits for exclusive or
       movwf   temp2;
loop:   movfw   temp2;
       addwf   temp2,f;        shift temp and set Z when done
       btfsc   STATUS,C;       check if next bit is set
       incfsz  temp1,f;
       btfss   STATUS,Z;       check if temp2 is now zero
       goto    loop;
       rrf     temp1,f;        get parity of random ^ 0xB4 into C
       rlf     random+1,f;     now shift random number to the left
       rlf     random,f;
...

Now if you initialize the random number to the same seed everytime,
you will always get the same pattern of numbers out.  So you might
want to try using the value of a timer initially to seed the pseudo-
random number generator, but make sure it is not zero.

Enjoy,

Peter.
--
Peter Homann   email: peterhspamKILLspamadacel.com.au       Work : +61 3 9596-2991
Adacel Pty Ltd                                   Fax  : +61 3 9596-2960
250 Bay St, Brighton 3186, VIC, AUSTRALIA      Mobile :     014 025-925
http://www.adacel.com.au     Australian Software Engineering Excellence

More... (looser matching)
- Last day of these posts
- In 1997 , 1998 only
- Today
- New search...