| |
Wanderer Account closed
Registered: Apr 2003 Posts: 478 |
Random number generation
I've been out of coding for so long that I no longer remember how to generate random numbers.
I remember I used to use a method where I'd pull a note from the SID chip music being played and add on the 'seconds' from the built in clock. It actually worked pretty good for my intentions.
I know BASIC has a RND function, and pardon me for asking but what method would YOU use to obtain a random number. There must be an easier method than what I'm using. I'm looking for an ASSEMBLY method :)
It's been so long, that I really forget all I ever learned :)
|
|
... 11 posts hidden. Click here to view all posts.... |
| |
Mace
Registered: May 2002 Posts: 1799 |
HCL: a way to not miss values is to use the random generator to sort a table instead of generating values.
If a number is missed, it means that the value will be the same as the table index.
Catch my drift?
Then again... if it's a fader you only use once, you could also just pre-calc the random and fix errors by hand ;-) |
| |
Monte Carlos
Registered: Jun 2004 Posts: 359 |
I have never done it, but i would try it the following way:
Start at an arbitrary x position, add a prime a little smaller than 320 and use the modulo it as the next x position. If i am right, all the x coordinates should be returned exactly one time until you reach a common multiple of your prime an 320.
Monte
|
| |
Partz Account closed
Registered: Jun 2008 Posts: 17 |
Quote: Waking up this thread again :). Is there any known way to modify the eor-feedback routine (see latest post by Graham) to generate *a bit more* predictable values?.. What i'm after is to have values that increase, but still are a bit random, keeping the property of not missing any values.
What i want to do is a fade-effect which fills the screen with dots/pixels from right to left in a random manner. Something like:
for i=0 to 319
xpos = i + 5*rnd(0)
next i
The above basic shit will of course miss some values and returning other values twice, and.. it's in basic :P. Any ideas?
I did something similar to this on the PC in C. I plotted n number of pixels per frame some of which were duplicated and some pixels never hit at all. At a certain point in time enough of the screen is filled with pixels such that doing a screen wipe still gives the perception that the screen was filled by the random number generator. It didn't matter that my random number generator didnt cover all values. |
| |
HCL
Registered: Feb 2003 Posts: 728 |
@Partz: OMG, that sounds like the way i *don't* want to do it :).
@Mace: Hmm, sorting a table!? I don't want to sort, i want numberzzz ;). ..and precalcing is not the answer either, but thnx anyways :).
@Monte Carlos: Yeah!! That's the kind of answer i want. But.. sounds too complicated to even try :/. Well, let's say we have 0-39 instead of 319.. I start with x = 7. Add prime smaller than 40 = 37, i get 7 + 37 = 44. then i do modulo 39 -> 4. Hmm, i get the sequence.. 7,4,1,38,35,33,30,27.. a bit too predictable ;). Need some magic eor shit also, don't i? |
| |
Shadow Account closed
Registered: Apr 2002 Posts: 355 |
That White Flame 0-ff randomizer is great, I am so stealing that for my BASIC-screen remove effect! |
| |
Mace
Registered: May 2002 Posts: 1799 |
HCL wrote:
Quote:Hmm, sorting a table!? I don't want to sort, i want numberzzz ;) Sure, but you know what the range is, right? Then put that in a table and random re-arrange/sort those...
But I think you're smart enough to understand what I meant the first time, so... have it your way ;) |
| |
HCL
Registered: Feb 2003 Posts: 728 |
@Mace: Oh, so you mean.. start with a linear table from 0 to (range - 1). Then randomly scramble *a little* using bouble sort.. Ah, there the sort comes in :). Is that it? Hehe sounds really cute :). |
| |
Monte Carlos
Registered: Jun 2004 Posts: 359 |
Perhaps my fault was to choose a prime close to 40.
Starting at zero, 17 gives: 0,17,34,11,28,5,22,9,26,3,20,37,14,...
This is much more random. Perhaps the clue lies in the finding of a suitable prime.
I'll try this @ home. It's bugging me too, now!
Monte
|
| |
Mace
Registered: May 2002 Posts: 1799 |
HCL wrote:
Quote:@Mace: Oh, so you mean.. start with a linear table from 0 to (range - 1). Then randomly scramble *a little* using bouble sort.. Ah, there the sort comes in :). Is that it? Hehe sounds really cute :). Indeed.
See, I didn't underestimate you ;-) |
| |
Monte Carlos
Registered: Jun 2004 Posts: 359 |
@HCL:
I tried my idea now, and it suxx. Don't do it this way.
Monte
|
Previous - 1 | 2 | 3 - Next |