|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Psuedorandom numbers
Well I have been studying psuedorandom sequences for Microchip microcontrollers based on seeds and so far the fastest I have found is thusly from mondo technology:
Code:
chop movf val1,w ;get the 1st
addwf val2,w ;add the 2nd
movwf val2 ;store the 2nd
addwf val3,w ;add the 3rd & store
movwf val3 ;back in 3rd
addwf val1 ;add back to 1st
swapf val1 ;swap nibbles
movf val1,w ;return one byte
ret
Last edited by Los Frijoles : 21-04-2008 at 22:55. Reason: Citing my sources... |
|
#2
|
|||||
|
|||||
|
Re: Psuedorandom numbers
Quite a bit longer than 10 instruction cycles but here is what our prof made us use for a lab earlier this year:
static unsigned long int SEED_X = 521288629L; // this is a 32-bit constant static unsigned long int SEED_Y = 362436069L; // this is a 32-bit constant unsigned int random() { static unsigned int a = 18000, b = 30903; SEED_X = a*(SEED_X&65535) + (SEED_X>>16); // requires 16X16 multiply, 32bit add SEED_Y = b*(SEED_Y&65535) + (SEED_Y>>16); // requires 16X16 multiply, 32bit add return (SEED_X + SEED_Y)/2; // requires 32bit add, 32bit shift } We had to implement this in ASM for our Lab before we started C so I have an ASM implementation, if you want to see it PM me. |
|
#3
|
|||
|
|||
|
Re: Psuedorandom numbers
use a linear congruential generator - probably the best in terms of ease of use to simplicity ratio. It's on wikipedia
-Salik |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Rounding numbers | teh_pwnerer795 | Programming | 13 | 17-12-2006 12:16 |
| Negative numbers? | Calvin | Programming | 6 | 09-02-2005 10:46 |
| Part Numbers | DDRAngelKurumi | Kit & Additional Hardware | 1 | 29-01-2005 18:38 |
| pwm numbers | CharlieWilken | Programming | 2 | 15-03-2004 01:15 |
| Team Numbers | archiver | 2000 | 2 | 24-06-2002 00:24 |