Announcement

Collapse
No announcement yet.

Random is not Random?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ESPsupport
    replied
    Random numbers are not truly random, see the description for the RAND and SEED functions.

    As those references show the values will repeat every time the display is reset or power cycled.

    The only way to 'solve' this is to get a truly random number to use as the seed, but this must come from somewhere outside of the display.

    Maybe you could use an RTC?

    If the user used touch input you could probably use sys_T() when the first touch was pressed.

    Maybe you can use sys_T() after the uSD is mounted. It might give you a (very?) slight variability, depending on how long the uSD takes to initialize

    A better way might be to take off directly from your power transformer where it's AC. Turn the value into 0-3.3v and feed into an analogue input, then use the value as the SEED

    Leave a comment:


  • kapsreiter
    replied
    the problem is that it always will play

    1
    2
    3
    4
    5

    when i mod the paramaters vor example 4 should be played less

    it will play
    1
    2
    3
    5

    but for example starts never with 2 or 3 or 4






    );
    pause(200);
    wend
    endif
    gfx_ScreenMode(LANDSCAPE) ; // change manually if orientation change
    gfx_Cls();

    SEED(4);

    repeat
    VideoIndex := RANDVAL(0,100); // Select Random Video number

    if ( VideoIndex >= 10 && VideoIndex < 19)
    mem_Free (hndl);
    hndl := file_LoadImageControl("Video1.dat", "Video1.gci", 1);
    frames := img_GetWord(hndl, iVideo1, IMAGE_FRAMES);
    for (frame := 0; frame < frames; frame++)
    img_SetWord(hndl, iVideo1, IMAGE_INDEX, frame) ;
    img_Show(hndl,iVideo1) ;
    //pause(1) ; // delay after each frame, does not include time to actually display frame
    next
    endif

    if ( VideoIndex >= 20 && VideoIndex < 39)
    mem_Free (hndl);
    hndl := file_LoadImageControl("Video2.dat", "Video2.gci", 1);
    frames := img_GetWord(hndl, iVideo1, IMAGE_FRAMES);
    for (frame := 0; frame < frames; frame++)
    img_SetWord(hndl, iVideo1, IMAGE_INDEX, frame) ;
    img_Show(hndl,iVideo1) ;

    //pause(1) ; // delay after each frame, does not include time to actually display frame
    next
    endif

    if ( VideoIndex >= 40 && VideoIndex < 59)
    mem_Free (hndl);
    hndl := file_LoadImageControl("Video3.dat", "Video3.gci", 1);
    frames := img_GetWord(hndl, iVideo1, IMAGE_FRAMES);
    for (frame := 0; frame < frames; frame++)
    img_SetWord(hndl, iVideo1, IMAGE_INDEX, frame) ;
    img_Show(hndl,iVideo1) ;

    //pause(1) ; // delay after each frame, does not include time to actually display frame
    next
    endif

    if ( VideoIndex >= 60 && VideoIndex < 79)
    mem_Free (hndl);
    hndl := file_LoadImageControl("Video4.dat", "Video4.gci", 1);
    frames := img_GetWord(hndl, iVideo1, IMAGE_FRAMES);
    for (frame := 0; frame < frames; frame++)
    img_SetWord(hndl, iVideo1, IMAGE_INDEX, frame) ;
    img_Show(hndl,iVideo1) ;
    //pause(1) ; // delay after each frame, does not include time to actually display frame
    next
    endif

    if ( VideoIndex >= 90 && VideoIndex < 99)
    mem_Free (hndl);
    hndl := file_LoadImageControl("Video5.dat", "Video5.gci", 1);
    frames := img_GetWord(hndl, iVideo1, IMAGE_FRAMES);
    for (frame := 0; frame < frames; frame++)
    img_SetWord(hndl, iVideo1, IMAGE_INDEX, frame) ;
    img_Show(hndl,iVideo1) ;
    //pause(1) ; // delay after each frame, does not include time to actually display frame
    next
    endif

    // To expand, just add more if-statements here

    forever
    endfunc

    Leave a comment:


  • Jerson
    replied
    Hello Kapsreiter,

    Random digits generated by RANDVAL(0,5) is generated by this equation ABS( (RAND()%(high-low)+low) ); the output is just the modulo of the the output of the RAND function.
    You could try creating a new function with larger pool of numbers for giving a more random digit, from this you can create some kind of function for further randomizing the digit you need. Getting a random number from 1 to 5 is just too limited since there is a lesser choice of number.

    Best Regards,

    Leave a comment:


  • kapsreiter
    started a topic Random is not Random?

    Random is not Random?

    hi

    i use this code

    but the random function will always play the videos from 1 to 5 not random

    any ideas?

    thx
    tom

    ________________________________________


    #platform "Gen4-uLCD-24D"

    // Program Skeleton 1.3 generated 28.02.2018 22:50:07

    #inherit "4DGL_16bitColours.fnc"

    #inherit "VisualConst.inc"

    #inherit "videoConst.inc"

    func main()
    var frame, frames ;
    var VideoIndex;

    putstr("Mounting...\n");
    if (!(file_Mount()))
    while(!(file_Mount()))
    putstr("Drive not mounted...");
    pause(200);
    gfx_Cls();
    pause(200);
    wend
    endif
    gfx_ScreenMode(LANDSCAPE) ; // change manually if orientation change
    gfx_Cls();

    repeat
    VideoIndex := RANDVAL(0,5); // Select Random Video number

    switch ( VideoIndex )

    case 0:
    hndl := file_LoadImageControl("Video1.dat", "Video1.gci", 1);
    frames := img_GetWord(hndl, iVideo1, IMAGE_FRAMES);
    for (frame := 0; frame < frames; frame++)
    img_SetWord(hndl, iVideo1, IMAGE_INDEX, frame) ;
    img_Show(hndl,iVideo1) ;
    //pause(1) ; // delay after each frame, does not include time to actually display frame
    next
    mem_Free(hndl);
    break;

    case 1:
    hndl := file_LoadImageControl("Video2.dat", "Video2.gci", 1);
    frames := img_GetWord(hndl, iVideo1, IMAGE_FRAMES);
    for (frame := 0; frame < frames; frame++)
    img_SetWord(hndl, iVideo1, IMAGE_INDEX, frame) ;
    img_Show(hndl,iVideo1) ;
    //pause(1) ; // delay after each frame, does not include time to actually display frame
    next
    mem_Free(hndl);
    break;

    case 2:
    hndl := file_LoadImageControl("Video3.dat", "Video3.gci", 1);
    frames := img_GetWord(hndl, iVideo1, IMAGE_FRAMES);
    for (frame := 0; frame < frames; frame++)
    img_SetWord(hndl, iVideo1, IMAGE_INDEX, frame) ;
    img_Show(hndl,iVideo1) ;
    //pause(1) ; // delay after each frame, does not include time to actually display frame
    next
    mem_Free(hndl);
    break;

    case 3:
    hndl := file_LoadImageControl("Video4.dat", "Video4.gci", 1);
    frames := img_GetWord(hndl, iVideo1, IMAGE_FRAMES);
    for (frame := 0; frame < frames; frame++)
    img_SetWord(hndl, iVideo1, IMAGE_INDEX, frame) ;
    img_Show(hndl,iVideo1) ;
    //pause(1) ; // delay after each frame, does not include time to actually display frame
    next
    mem_Free(hndl);
    break;

    case 4:
    hndl := file_LoadImageControl("Video5.dat", "Video5.gci", 1);
    frames := img_GetWord(hndl, iVideo1, IMAGE_FRAMES);
    for (frame := 0; frame < frames; frame++)
    img_SetWord(hndl, iVideo1, IMAGE_INDEX, frame) ;
    img_Show(hndl,iVideo1) ;
    //pause(1) ; // delay after each frame, does not include time to actually display frame
    next
    mem_Free(hndl);
    break;

    // To expand, just add more cases here

    endswitch
    forever
    endfunc
    _______________________________________

    Last edited by kapsreiter; 4th March 2018, 08:24 PM.
Working...
X