Like Tree1Likes
  • 1 Post By Nominal Animal

random number

This is a discussion on random number within the C Programming forums, part of the General Programming Boards category; input: 8 numbers output:a random number between 1-100 base on the input numbers any idea for doing this ?...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    34

    random number

    input: 8 numbers
    output:a random number between 1-100 base on the input numbers
    any idea for doing this ?

  2. #2
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    641
    Post some code first. As far as the random number goes, read this SRAND - set seed for random number generation.

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    34
    i know how s rand and rand work but if i use them its not base on the numbers!
    i want the program choose random numbers in some rule
    for example if more than half of numbers are lower than 1000 the chance for give output numbers that are lower than 50 increese by 20 percent or sth like this!

  4. #4
    qny
    qny is offline
    Registered User
    Join Date
    Sep 2012
    Posts
    355
    Why?

    Anyway, here's an approach. (Why anyone would use it rather than a direct rand() value is beyond me though)

    Code:
    int randbased(input *array) // input is in array[0] to array[7]
    {
        int k, s = 0;
        for (k = 0; k < 8; k++) s += input[k];
        for (k = 0; k < s; k++) rand(); /* ignore s random numbers */
        return rand();
    }

  5. #5
    Registered User
    Join Date
    Oct 2011
    Posts
    872
    Quote Originally Posted by king_zart View Post
    i want the program choose random numbers in some rule
    We are neither telepathic nor omniscient, you know.

    You need to define those rules for us to be able to help you.

    If you don't know the rules, but can show a complete set of inputs and outputs, then we can help you deduce the rules. Then we can help you implement those rules in code. But we cannot divine your wishes.

    Please be specific, as vague partial examples are just frustrating to everyone. We need detailed, specific information, to help you.
    camel-man likes this.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Quote Originally Posted by king_zart View Post
    input: 8 numbers
    output:a random number between 1-100 base on the input numbers
    any idea for doing this ?
    Yes hundreds of ideas in fact.
    E.g CRC + LCG PRNG + MOD.
    Just write some code that does something. Anything you can do, no matter how simple it is to begin with, would be great.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #7
    Registered User
    Join Date
    Oct 2012
    Posts
    34
    as i said before i want the program do this...
    Code:
    #include <stdio.h>
    int main()
    {
    int a[8];
        int i,b;
        for(i=0;i<8;i++)
        scanf("%d",&a[i]);
    for(i=0;i<8;i++)
    if(a[i]<100)
    b++;
    if(b>4)
    //give a random number lower than 200 that its chance for become lower than 100 is 2times more than becom higher than 100
    {}
    }
    Last edited by king_zart; 11-06-2012 at 03:51 AM.

  8. #8
    qny
    qny is offline
    Registered User
    Join Date
    Sep 2012
    Posts
    355
    Generate a random number between 0 and 300.
    If it is greater or equal to 200, subtract 200, getting a new number between 0 and 100.

    Result: numbers between 0 and 100 are twice more likely to come up than numbers between 100 and 200.

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Yeah I can't help you, you keep adding random weird requirements every time you post.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need a random number generator thats not compleatly random
    By thedodgeruk in forum C++ Programming
    Replies: 1
    Last Post: 06-05-2011, 07:48 AM
  2. Replies: 5
    Last Post: 10-05-2009, 11:21 AM
  3. Replies: 2
    Last Post: 12-25-2003, 01:31 AM
  4. random number between negative and positive number
    By anomaly in forum C++ Programming
    Replies: 6
    Last Post: 12-06-2003, 08:40 AM
  5. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 05:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21