Options

How to use Random Function using Arrays in C/AL

alwaysgunaalwaysguna Member Posts: 45
hi

I like to know that, how to use a Random Function Using Arrays.
Actually i am created a Question Bank Report. so, i want to fetch the questions randomlly.

so, i want to know how to use a random function with arrays.
Guna

Comments

  • Options
    Tim81Tim81 Member Posts: 68
    LOL!

    Do you work together with Madhan?

    Look, i answered here:
    http://www.mibuso.com/forum/viewtopic.php?t=6515
  • Options
    jemmyjemmy Member Posts: 247
    In my minds...

    tQuestion is a temporary table...
    WHILE tQuestionBank.GET (FORMAT(RANDOM(count)+1)) DO
    BEGIN
          
          // process your record here      
    
          tQuestionBank.DELETE;
          count := count - 1;
    END;
    

    Haven't tried the code yet.

    HTH,

    Jemmy
  • Options
    Tim81Tim81 Member Posts: 68
    jemmy wrote:
    WHILE tQuestionBank.GET (FORMAT(RANDOM(count)+1)) DO
    BEGIN
          
          // process your record here      
    
          tQuestionBank.DELETE;
          count := count - 1;
    END;
    
    Why do you write RANDOM(COUNT)+1? RANDOM returns a number between 1 and the number you entered in the brakes. Sy why do you need the '+1'?
  • Options
    jemmyjemmy Member Posts: 247
    Hi Tim81,

    You are correct! Thanks.
    Hmm, I just think this is not an easy case...

    Cheers,

    Jemmy
  • Options
    Tim81Tim81 Member Posts: 68
    Where is the problem? Your code should work. I made a similar code example in the other thread, linked in my post above. You just have to fill a temporary table with continous IDs, so that the GET is working.
  • Options
    jemmyjemmy Member Posts: 247
    I just wrote the following codes:
    QuestionBank.SETCURRENTKEY ("No.");
    QuestionBank.SETFILTER ("No.",'>0');
    count := QuestionBank.COUNT;
    IF QuestionBank.FIND('-') THEN
       REPEAT
          temp.INIT;
          temp := QuestionBank;
          temp.INSERT;
       UNTIL QuestionBank.NEXT = 0;
    
    WHILE temp.GET(FORMAT(RANDOM(count))) DO
    BEGIN
       temp.DELETE;
       count := count - 1;
    END;
    

    How do you ensure that all records in the bank are fetched completely? :?:
    Let me know.

    Jemmy
Sign In or Register to comment.