Search the web
Sign In
New User? Sign Up
gbadev
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Random number function   Message List  
Reply | Forward Message #14665 of 15019 |
Re: [gbadev] Random number function

i've used this for several commercial gba games. it's fast, simple, and
time-tested. mersenne twister-strength algorithms are generally not needed
for game-specific needs. no need to do the mode switch to ARM for so few
lines of assembly:

// C++ code
enum
{
RAND_SLOPE = 0x41c64e6d,
RAND_INTERCEPT = 0x3039,
RAND_SEED = 1,
};

static unsigned int sRandomPlant = RAND_SEED;

int rand()
{
sRandomPlant = (sRandomPlant * RAND_SLOPE) + RAND_INTERCEPT;
return static_cast<int>(sRandomPlant >> 17); // RAND_MAX = 0x7fff
}

// THUMB asm
RAND_SEED = 1
RAND_SLOPE = 0x3039
RAND_INTERCEPT = 0x41c64e6d

.data

randPlant:
.word RAND_SEED

.text
.thumb

.thumb_func
rand:
ldr r3, =randPlant
ldr r0, [r3]
ldr r1, intercept
ldr r2, slope
mul r0, r0, r2
add r0, r0, r1
str r0, [r3]
lsr r0, #17
bx lr

regards,
matt.

----- Original Message -----
From: "Graeme Cowie" <mcgeezer@...>
To: <gbadev@yahoogroups.com>
Sent: Tuesday, December 09, 2003 3:02 PM
Subject: [gbadev] Random number function


Hi gbadev forum,

Rather than re-invent the wheel trying to write an ARM random number
gernerator function, i thought i'd ask if anyone has done this before or if
there is an easy fast way to achieve random numbers.

I'm thinking of doing a GBA conversion of the classic Atari 8bit version of
River Raid, which generates terrain and enemies randomly.

Cheers,

McGeezer





Wed Dec 10, 2003 1:31 pm

whatwouldbig...
Online Now Online Now
Send Email Send Email

Forward
Message #14665 of 15019 |
Expand Messages Author Sort by Date

Hi gbadev forum, Rather than re-invent the wheel trying to write an ARM random number gernerator function, i thought i'd ask if anyone has done this before or...
Graeme Cowie
mcgeezer22
Offline Send Email
Dec 9, 2003
8:17 pm

Three words: Linear Congruental Generator ... -- http://dreamcache.mine.nu...
Tomas Hallenberg
tomha219@...
Send Email
Dec 9, 2003
9:39 pm

Take a look at the Mersenne Twister, or the Mitchell Moore algorithm. Both of them are fast, good and don't require too much memory. Guido ... From: Graeme...
Guido Henkel
guidohenkel
Offline Send Email
Dec 9, 2003
9:39 pm

Man, I lost so much of my childhood to that game :) There was a thread on this mailing list ages ago about this. Try searching the archives for "mersenne...
alex mole
lordBosh
Offline Send Email
Dec 9, 2003
10:11 pm

i've used this for several commercial gba games. it's fast, simple, and time-tested. mersenne twister-strength algorithms are generally not needed for...
matthew conte
whatwouldbig...
Online Now Send Email
Dec 10, 2003
2:36 pm

Hi, I've been trying to get a C++ project to compile using Devkit Advance (release 5 beta 3) ideally along with Jeff's Crt0 and LnkScript (crtls v1.28). Which...
gbadev@...
relaxed_n_ch...
Offline Send Email
Dec 11, 2003
9:54 pm

Actually, In your makefile, instead of gcc .....(options) type g++ .... (options). The libraries should (don't quote me on it though) automatically be linked...
dagamer34
Offline Send Email
Dec 12, 2003
4:16 am

... Hash: SHA1 ... I'm pretty sure gcc is the same as g++ when it's called with a .cpp extention... ... Version: GnuPG v1.2.3 (GNU/Linux) ...
Luke-Jr
Luke7Jr
Offline Send Email
Dec 12, 2003
7:07 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help