Author Topic: Random Character  (Read 16416 times)

Mike Lobanovsky

  • Guest
Re: Random Character
« Reply #45 on: September 26, 2016, 11:13:58 AM »
I'm happy with the RANDOMIZE / RND functions in Script BASIC if properly seeded. I think you can get a good visual of the random effect by looking at the One Line Graphic post I made.

John,

If you don't believe me then probably you'd believe what Peter Verhas has to say in this regard?

Quote from: SB sources
/**RND
=section math
=display RND()

Returns a random number as generated by the C function T<rand()>. Note that this random number generator usually provided by the libraries implemented for the C compiler or the operating system is not the best quality ones.
If you need really good random number generator then you have to use some other libraries that implement reliable RND functions.
*/
COMMAND(RND)
#if NOTIMP_RND
NOTIMPLEMENTED;
#else

  /* this is an operator and not a command, therefore we do not have our own mortal list */
  USE_CALLER_MORTALS;
  RETURN_DOUBLE_VALUE( rand() )

#endif
END

/**RANDOMIZE
=section math
=display RANDOMIZE

Seed the random number generator. If the command is presented without argument the random number generator is seed with the actual time. If argument is provided the random number generator is seed with the argument following the keyword T<RANDOMIZE>.
*/
COMMAND(RANDOMIZA)
#if NOTIMP_RANDOMIZA
NOTIMPLEMENTED;
#else
  time_t timer;
  srand(time(&timer));

#endif
END

COMMAND(RANDOMIZE)
#if NOTIMP_RANDOMIZE
NOTIMPLEMENTED;
#else
  time_t timer;
  NODE nItem;
  VARIABLE ItemResult;

  nItem = PARAMETERNODE;
  if( nItem ){
    ItemResult = _EVALUATEEXPRESSION_A(nItem);
    ASSERTOKE;
    if( ItemResult )
      srand(GETLONGVALUE(ItemResult));
    else
      srand(time(&timer));
    }else{
    srand(time(&timer));
    }

#endif
END

jj2007

  • Guest
Re: Random Character
« Reply #46 on: September 26, 2016, 04:35:02 PM »
if we want to do anything serious, we should resort to specialized 3rd party libraries.

There is a good overview here - a few thousand. MasmBasic's built-in Rand() is also in the list.

ScriptBasic

  • Guest
Re: Random Character
« Reply #47 on: September 26, 2016, 04:47:31 PM »
Quote
If you don't believe me then probably you'd believe what Peter Verhas has to say in this regard?

I never said I didn't believe you or Peter. All I said is I'm happy with the results I have obtained with SB randomizing. If there comes a day where a better resolution (like the gfx_time() replacement for NOW) RND then I'll create an C extension module function for it.



« Last Edit: September 26, 2016, 04:49:05 PM by John »

Mike Lobanovsky

  • Guest
Re: Random Character
« Reply #48 on: September 26, 2016, 09:54:01 PM »
MasmBasic's built-in Rand() is also in the list.

Wow, that's real cool, Jochen!

My compliments! :)


P.S.  I'm not a member of the MASM community and thus have no access to the thread you're referring to:
Quote from: JJ
- credits to Alex Bagayev for his AxRand algo
Could you possibly reveal his description of the algo and sources, if any, to us too?
« Last Edit: September 27, 2016, 12:05:19 AM by Mike Lobanovsky »