biased random numb generation

This is a discussion on biased random numb generation within the C Programming forums, part of the General Programming Boards category; hi everyone i need to generate a bunch of random numbers that will be influenced by some number (a positive ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    12

    biased random numb generation

    hi everyone

    i need to generate a bunch of random numbers that will be influenced by some number (a positive integer say up to a 1000) and i need to have these biased random numbers within a certain range (from 1 to 44).

    i managed to generate purely random numbers within my range
    witht the rand function:

    Code:
    some_array[i] = rand() % 45;
    but how do i influence the rnd number generation?

  2. #2
    Registered User
    Join Date
    Nov 2003
    Posts
    46
    I'm not sure I understand what you mean by biased random number or influenced. Do you want more of the generated numbers to be in a certain region from 1 to 44. For example, do you want something like this?

    sometimes the random number is between 1 to 21

    often the random number is between 21 and 33

    usually the random number is between 33 to 44

    If this is what you want I think I know how to do what you want and I'll explain.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    Are you talking about generating numbers with a poisson distribution, where values closer to the mean are more likely than those at the limits?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    12
    nothng too fancy. i was thinking more a random number multiplied with some fixed number. this way the result will still be random but not purely random as it would be with just using rand()

    i tried this code:

    Code:
    array[i] = (y * rand()) % 45;
    where y is some integer.
    now this thing sometimes works and sometimes it doesnt.
    when i run it sometimes it gives me zeros and other times positiver integres up to 44 (as i want). why dooes it give me zeros sometimes?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    > why dooes it give me zeros sometimes?
    Because x % N
    produces results in the range 0..N-1

    If you want 1..N, then its
    x % N + 1
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rapid random number generation problem
    By Newton in forum C Programming
    Replies: 17
    Last Post: 09-19-2008, 03:08 PM
  2. Diablo's random level generation
    By glo in forum Game Programming
    Replies: 7
    Last Post: 07-19-2008, 04:04 AM
  3. non repeating random number generation?
    By gencor45 in forum C# Programming
    Replies: 1
    Last Post: 02-08-2005, 05:23 PM
  4. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 05:51 PM
  5. fast random number generation
    By Heraclitus in forum C Programming
    Replies: 4
    Last Post: 02-09-2003, 07:48 PM

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