Random number seed


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Two questions:

    1. In your code above, you have the following.
    Code:
    IF W0 < 13105 Then loop1
    IF W0 < 26210 Then loop2
    IF W0 < 39315 Then loop3
    IF W0 < 52420 Then loop4
    IF W0 <= 65525 Then loop5
    Lets take W0=10000 then all of these IF statements will be true and be executed. Or say W0=28000; in this case last three IF statements will be executed, etc...

    You should change it as follows.
    Code:
    IF W0 < 13105 Then 
    	loop1
    ELSE
    	IF W0 < 26210 Then 
    		loop2
    	ELSE
    		IF W0 < 39315 Then 
    			loop3
    		ELSE
    			IF W0 < 52420 Then 
    				loop4
    			ELSE
    				IF W0 <= 65525 Then loop5
    			ENDIF
    		ENDIF
    	ENDIF
    ENDIF

    OR use a select case, it would make it easier to follow the logic.

    2. Forget this one.


    ---------------------------

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Post

    Hi,

    There was a thread about random numbers, here ... sometimes ago.
    Conclusion was Microchip offers the best routine ( assembler ... yes ! ) in its applications.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Sorry to jump in.....

    Hi,
    Sayzer wrote:
    1. In your code above, you have the following.

    Code:
    IF W0 < 13105 Then loop1
    IF W0 < 26210 Then loop2
    IF W0 < 39315 Then loop3
    IF W0 < 52420 Then loop4
    IF W0 <= 65525 Then loop5

    Lets take W0=10000 then all of these IF statements will be true and be executed. Or say W0=28000; in this case last three IF statements will be executed, etc...
    Why is that?
    If W0=10000 the first IF statement tests true and the program jumps to the Loop1 routine which is executed. At the end of Loop1 the program jumps to Test where a new RANDOM is executed and assigned to W0. Lets say it's 28000 as in you example. The third statement tests true and the program jumps to Loop3, executes it and then starts over with another RANDOM. At least that's how I read it.

    HTH
    /Henrik Olsson.

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    You seem to be having it correct Henrik.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

Similar Threads

  1. Random Numbers
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 18th December 2008, 09:47
  2. Random seed using the ds1307 RTC
    By rookie11 in forum General
    Replies: 7
    Last Post: - 25th November 2007, 21:31
  3. Working with the random number generator
    By kwelna in forum mel PIC BASIC
    Replies: 9
    Last Post: - 16th January 2007, 18:50
  4. Random number results
    By bartman in forum mel PIC BASIC
    Replies: 3
    Last Post: - 9th March 2005, 18:39
  5. more random number questions
    By bartman in forum mel PIC BASIC
    Replies: 1
    Last Post: - 14th November 2004, 18:55

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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