RANDOM() a litle bit more random please...
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by FAKEFACTORY.
Hi,
i there any way to make more random random-numbers out of the RANDOM() function? I.e. RANDOM(7)+1 for random numbers between 1 and 8 gives me
mainly:
1,1,1,1,5,5,5,1,5,5,5,1,....
This is a little bit to static for a random generator. Can we "load" the function with a randomizer-seed, like CurrentTicks? Or is there another Random-generator sourcecode avaiable?
Registered PureBasic Coder
Hi,
i there any way to make more random random-numbers out of the RANDOM() function? I.e. RANDOM(7)+1 for random numbers between 1 and 8 gives me
mainly:
1,1,1,1,5,5,5,1,5,5,5,1,....
This is a little bit to static for a random generator. Can we "load" the function with a randomizer-seed, like CurrentTicks? Or is there another Random-generator sourcecode avaiable?
Registered PureBasic Coder
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by El_Choni.
Hi, try this code:
Bye,
El_Choni
Edited by - El_Choni on 03 February 2002 17:23:47
Hi, try this code:
Code: Select all
Global result.l
max.l
seed.l
!Extern _GetTickCount@0
!call _GetTickCount@0
!mov [v_seed], eax
Procedure.l MyRandom(max.l) ; don't use 0 as max, or fires a division by 0 error (avoidable, but would make it slower)
!mov [v_max], eax
!mov eax, [v_seed]
!mov dword ecx, $41c64e6d
!mul ecx
!add dword eax, $3039
!And dword eax, $7ffffff
!mov [v_seed], eax
!mov ecx, [v_max]
!sub edx, edx
!div ecx
!mov [v_result], edx
ProcedureReturn result
EndProcedure
result = MyRandom(7)
MessageRequester("Random result:", Str(result), 0)
El_Choni
Edited by - El_Choni on 03 February 2002 17:23:47
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by El_Choni.
"reseed off"? I don't understand. the GetTickCount call is used to get a different seed each time, precisely to avoid what you say.
I got this code from the Win32asm message board. There are several other pseudorandom number generators there, check it if you wish.
Bye,
El_Choni
"reseed off"? I don't understand. the GetTickCount call is used to get a different seed each time, precisely to avoid what you say.
I got this code from the Win32asm message board. There are several other pseudorandom number generators there, check it if you wish.
Bye,
El_Choni
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by MrVainSCL.
Hi El_Choni
Many many thanks for your suppport to optimize the Random() and Str() commands... The new Random() works very fine... I must test the Str() replace... Anyway many thanks for the friendly and fast support - now my program is a bit smaller
) Would be nice to see the feature in next PB where danilo told about... Link only needed stuff to a file (obj) ...
) This would be very welcome Fred! 
PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...
greetz
MrVainSCL! aka Thorsten
Hi El_Choni
Many many thanks for your suppport to optimize the Random() and Str() commands... The new Random() works very fine... I must test the Str() replace... Anyway many thanks for the friendly and fast support - now my program is a bit smaller



PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...
greetz
MrVainSCL! aka Thorsten
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by El_Choni.
Bye,
El_Choni
He, he, I saw my error and corrected it, but thought that your post was made after the correction.You have since edited the version posted.
The version I copy and pasted had a set seed (seed.l=5555), it did not have the GetTickCount.
Bye,
El_Choni
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by MrVainSCL.
PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...
greetz
MrVainSCL! aka Thorsten
sorry... the lib will be coded in pure x86 code... also it dont want run on 680x0 amiga os for example...is this for any OS? -jb
PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...
greetz
MrVainSCL! aka Thorsten
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by El_Choni.
Tron, if you talk about the randomizing procedure, it must be easy to translate (anyway, PB Amiga will be updated soon and will likely include the Random() function, I guess).
Here's a rough translation using 86TO68:
See you,
Edited by - El_Choni on 04 February 2002 18:44:46
Tron, if you talk about the randomizing procedure, it must be easy to translate (anyway, PB Amiga will be updated soon and will likely include the Random() function, I guess).
Here's a rough translation using 86TO68:
Code: Select all
Data:
seed: dc.l 0
Code:
PB_InitRandom:
jsr _GetTickCount@0 ; this should be changed to some Amiga API function which puts the result in d0
move.l d0,seed
rts
PB_Randomize:
move.l d0,-(a7)
move.l seed(pc),d0
move.l #1103515245,d2
add.l #12345,d0
and.l #134217727,d0
move.l d0,seed
move.l (a7)+,d2
sub.l d3,d3
move.l d0,d5
move.l d3,d0
move.l d5,d3
rts
Edited by - El_Choni on 04 February 2002 18:44:46
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by El_Choni.
I think that what is so fast now is your computer
. I'm going to install it again, but don't know where to find a good assembler to test things, and CygnusEd, (oh, well, and so much other things that don't come with UAE, of course).
Have a nice day,
El_Choni
I think that what is so fast now is your computer

Have a nice day,
El_Choni
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm