View Single Post
  #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)