CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2013
    Posts
    5

    how to break repeating random

    hi guys any one can help me out for this problem..
    i create a fuction to generate all the question. also this fuction have a random how can i put a code to break the repeting random.. thanks
    here my sample code

    Code:
    Public Function Generat1n()
    Dim j As Integer
    
    Open App.Path & "\Questions.mezz" For Input As #1
    
    j = Int(Rnd * 12)
    For i = 0 To j
    Line Input #1, question 
    Next i
    Label1.Caption = question
    Close #1
    
    End Function

    what will i insert code and where i will put?

  2. #2
    Join Date
    Jul 2005
    Posts
    1,083

    Re: how to break repeating random

    Use the RANDOMIZE function just before the RND line
    See some examples here ---> http://www.developerfusion.com/code/...andom-numbers/
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  3. #3
    Join Date
    Nov 2013
    Posts
    5

    Re: how to break repeating random

    thanks i use it but the random still repeating

  4. #4
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: how to break repeating random

    Okay your been very vague....

    "random still repeating" dies not help ... what we need to know is it :

    #1).. Every time you run the program the questions repeat in the same order !!

    #2).. The questions are random, but some of the question repeat every now and then...!!


    solutions:

    #1) randomize using the clock or ticker as a base number.

    #2) Keep track of which questions have been asked and skip them if they 'pop up' again...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  5. #5
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: how to break repeating random

    If you only want each question to be asked once then one option would be to load the entire file into a listbox at the beginning (form_load)
    Also put the call to Randomize in Form_Load

    When you want to get a question use the rnd in the range of 0 to listcount-1 to get a question from the list and then remove that question from the list
    This way you will get the questions asked in random order and will not get the same question twice
    Always use [code][/code] tags when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured