### Author Topic: Looking for alternative SEEDRND function  (Read 618 times)

#### MrPlow

• Prof. Inline
• Posts: 1721
##### Looking for alternative SEEDRND function
« on: 2019-Jul-29 »
Hi Guys

Looking for one that works without needing seedrnd?

Thks!
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

#### bigsofty

• Community Developer
• Prof. Inline
• Posts: 2675
##### Re: Looking for alternative SEEDRND function
« Reply #1 on: 2019-Aug-02 »
These are what I use in my game. Used mainly for speed, rather than just a set seed, should still do though for cross platform stuff.

Code: (glbasic) [Select]
`INLINE//================================================================================================// /*********************************************** ** Random seed ** ***********************************************///================================================================================================// int gRndSeed = 98371; void Seed(int seed) { gRndSeed = seed; }//================================================================================================// /*********************************************** ** Random number generator ** ***********************************************///================================================================================================// int Rand() { int k1; int ix = gRndSeed; k1 = ix / 127773; ix = 16807 * (ix - k1 * 127773) - k1 * 2836; if (ix < 0) ix += 2147483647; gRndSeed = ix; return gRndSeed; } float cRandFloat(float range) // 3 digits after decimal should be plenty for my app. { int iRange = (range* 1000); float result = (float)(Rand()%iRange); return result * 0.001f; }ENDINLINEFUNCTION SetSeed: seed% INLINE Seed( seed ); ENDINLINE ENDFUNCTIONFUNCTION GetSeed%: INLINE return gRndSeed; ENDINLINE ENDFUNCTIONFUNCTION RandInt%: range% INLINE return Rand()%(range); ENDINLINE ENDFUNCTIONFUNCTION RandFloat#: range# INLINE return cRandFloat((float)range); ENDINLINE ENDFUNCTIONFUNCTION RandFloatRange#: minFloat#, maxFloat# INLINE return cRandFloat((float)(maxFloat-minFloat))+minFloat; ENDINLINE ENDFUNCTIONFUNCTION RandIntRange%: minInt%, maxInt% INLINE return (Rand()%(maxInt-minInt))+minInt; ENDINLINE ENDFUNCTION`
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

#### MrPlow

• Prof. Inline
• Posts: 1721
##### Re: Looking for alternative SEEDRND function
« Reply #2 on: 2019-Aug-03 »
Thanks!
Will this work for PC and Mac?
Also, are those RND functions faster or slower
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

#### bigsofty

• Community Developer
• Prof. Inline
• Posts: 2675
##### Re: Looking for alternative SEEDRND function
« Reply #3 on: 2019-Aug-03 »
Should be faster and work the same on any platform.
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)