Go to Post In all seriousness, here's a thought for everyone: Don't worry about what you can't control. - Rich Kressly [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 21-04-2008, 22:55
Los Frijoles's Avatar
Los Frijoles Los Frijoles is offline
Stormin' Mormon
AKA: Kevin Cuzner
FRC #2062 (C.O.R.E.)
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2007
Location: Waukesha, WI
Posts: 27
Los Frijoles has a spectacular aura aboutLos Frijoles has a spectacular aura about
Send a message via AIM to Los Frijoles
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
It looks to be 10 instruction cycles long. However, I would like to see some other methods as I have found that this particular algorithm tends to repeat numbers after a short while with only a 24-bit seed. Does anyone else know of some psuedorandom sequences (C, ASM, or Psuedocode please)?
__________________
Community Of Robotic Engineers 2062





Blender totally pwns 3DS Max...

My life is here and here.

Cuznersoft Hardware and Software Development

Last edited by Los Frijoles : 21-04-2008 at 22:55. Reason: Citing my sources...
  #2   Spotlight this post!  
Unread 21-04-2008, 23:00
Vikesrock's Avatar
Vikesrock Vikesrock is offline
Team 2175 Founder
AKA: Kevin O'Connor
no team
Team Role: Engineer
 
Join Date: Mar 2006
Rookie Year: 2007
Location: Manchester, NH
Posts: 3,305
Vikesrock has a reputation beyond reputeVikesrock has a reputation beyond reputeVikesrock has a reputation beyond reputeVikesrock has a reputation beyond reputeVikesrock has a reputation beyond reputeVikesrock has a reputation beyond reputeVikesrock has a reputation beyond reputeVikesrock has a reputation beyond reputeVikesrock has a reputation beyond reputeVikesrock has a reputation beyond reputeVikesrock has a reputation beyond repute
Send a message via AIM to Vikesrock Send a message via MSN to Vikesrock Send a message via Yahoo to Vikesrock
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.
__________________


2007 Wisconsin Regional Highest Rookie Seed & Regional Finalists (Thanks 930 & 2039)
2008 MN Regional Semifinalists (Thanks 2472 & 1756)
2009 Northstar Regional Semifinalists (Thanks 171 & 525)
  #3   Spotlight this post!  
Unread 27-04-2008, 01:02
Salik Syed Salik Syed is offline
Registered User
FRC #0701 (RoboVikes)
Team Role: Alumni
 
Join Date: Jan 2003
Rookie Year: 2001
Location: Stanford CA.
Posts: 514
Salik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud of
Send a message via AIM to Salik Syed
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
__________________
Team 701
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 01:46.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi