RandomSeed with Maximum parameter

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

RandomSeed with Maximum parameter

Post by Mistrel »

RandomSeed(Value[, Maximum])
Note: each times a program start, a new seed is generated ..
If Random() always uses the same seed then this additional parameter for RandomSeed() would be nice.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

what would be the use of it? :?

the maximum is a parameter of Random, not of the Seed...

...

one thing I would like to see for Random() is several Rows with different Seeds...
oh... and have a nice day.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

I believe RandomSeed returns a long (or integer?). The Maximum parameter would provide an alternative upper-bounds for the return value. Or maybe I'm misunderstanding the function.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

RandomSeed() ensures that you always get the same numbers, even when you restart your program.

On first program start, you get the numbers

Code: Select all

1  57  34  296  346 ...
on second start, you get the numbers

Code: Select all

1  57  34  296  346 ...
and so on. The third start gives you the same numbers again. A maximum parameter for RandomSeed() is nonsense, you can use the maximum parameter provided by Random(). This parameter is independent from RandomSeed().

Btw, Random() returns a long.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post by Demivec »

AND51 wrote:Btw, Random() returns a long.
Actually it's an integer.
freak, regarding returntype of Random(), wrote:Note that you only get 64bits on x64 as the returntype is integer.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

the Seed is independent from the Range of the later called Random function.

this code:

Code: Select all

RandomSeed( 42 )
Debug Random( 4711 )
Debug Random( 4711 )
Debug Random( 10 )
Debug Random( 4711 )
always produces
866
2197
4
2483
and so it always should as a 32bit exe.

... wonder if it returns the same as a 64bit exe.
oh... and have a nice day.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

> ... wonder if it returns the same as a 64bit exe.

it returns the same.
quidquid Latine dictum sit altum videtur
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

good to know! thanx :mrgreen:
oh... and have a nice day.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Demivec wrote:Actually it's an integer.
Sorry, Sir. I seemingly messed it up.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post by Demivec »

AND51 wrote:
Demivec wrote:Actually it's an integer.
Sorry, Sir. I seemingly messed it up.
:wink: No disrepect intended, Sir.

I mentioned that to clarify that you are not limited to a Long value, except when compiling for 32-bit.
Post Reply