A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: what is Marital numbers code in ActionScript 3

  1. #1
    Senior Member
    Join Date
    May 2016
    Posts
    451

    what is Marital numbers code in ActionScript 3

    hi
    what is Marital numbers and odd numbers code in ActionScript 3

    Marital numbers is : 0 2 4 6 8 10 12 .....
    odd numbers is : 1 3 5 7 9 11 13 ....

    i want do this :

    var i:Marital numbers = Math.randomRange(0,20)
    var hdd numbers = Math.randomRange(0,20)
    Last edited by kofa; 12-16-2017 at 05:16 PM.

  2. #2
    Senior Member
    Join Date
    May 2016
    Posts
    451
    how can i do this :

    var i:Marital numbers = Math.randomRange(0,20)
    var hdd numbers = Math.randomRange(0,20)
    i > h ( " i " must be > "h")

  3. #3
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,834
    If you're trying to randomly generate an even or an odd number there's a simple way to do it. Basically just create a recursive function that will keep calling itself until it gets the proper number. This is a dirty way to do it however. Another way would be to use the original random number generator function. It basically generates a number between 0 to 1. With that you'd have to multiply it by the max number. Then you can round the number to the closes proper value. This is how I'd handle it.

    Edit: to your second question.
    Code:
    i > h ( " i " must be > "h")
    This would be a starting point. It could be a problem if i is ever = to 20 however.
    Code:
    hdd numbers = Math.randomRange(i,20)
    Last edited by swak; 12-18-2017 at 01:26 AM.
    .

  4. #4
    Senior Member
    Join Date
    May 2016
    Posts
    451
    thanks swak you always help me
    but i am sorry
    because my bad english language i dont understand your replay
    can you please edit my file


    Attached Files Attached Files

  5. #5
    Senior Member
    Join Date
    May 2016
    Posts
    451
    i found this link but i tired to get any thing:

    http://lab.kapit.fr/skin/frontend/de.../MathUtil.html

  6. #6
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,834
    I can't use swish. So I can't open your 'math code.swi' file. If you could point me to a Swish installer I could use then that would be different but it seems broken.

    Also, Marital in english has to do with marriage. So using that word here is confusing. After looking at things it looks like you mean the word 'even'. If you're confused by a word I suggest you use the search in google like this: "define: marital".

    I've created something that should do it:
    Code:
    function generateNum(range:Array, isEven:int=0):int {
    	//isEven should be == 0 for even numbers and == 1 for odd
    	var num:Number = range[0]+Math.random()*range[1];
    	return (int(num)%2==isEven?Math.floor(num):Math.ceil(num));
    }
    
    var even:int = generateNum([0,20],0);
    var odd:int = generateNum([0,even],1);
    The only problem with this is if even becomes 0. It will end up with both even and odd being 0.
    .

  7. #7

  8. #8
    Senior Member
    Join Date
    May 2016
    Posts
    451
    thanks swak
    now it working fine
    and excuse me for my bad english language

  9. #9
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,834
    No problem, the link you supplied didn't work. It was shortened. Could you fix it please?
    .

  10. #10
    Senior Member
    Join Date
    May 2016
    Posts
    451

  11. #11
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,834
    Thanks, that got it working.
    .

  12. #12
    Senior Member
    Join Date
    May 2016
    Posts
    451
    my respect for you swak

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

HTML5 Development Center