Re: Anyone have any ideas on this one.....



"joebenjamin" <guitarguy70@xxxxxxxxxxx> writes:

I am trying to write a program that will generate 100 random numbers
between 1 and 50. Using these numbers, I want to generate a list that will
tell the number of random numbers that fell between 1-5, 6-10, 11-15,
16-20, ... , and 46-50. Finally,I would like to print out the results as a
histogram. I have written it out and would think it would look like this.

1-5 (11) ***********
6-10 (8) ********
11-15 (12) ************
16-20 (9) *********
21-25 (10) **********
26-30 (11) ***********
31-35 (7) *******
36-40 (8) ********
41-45 (13) *************
46-50 (11) ***********

I am trying to learn how to do this and I am stuck. Any suggestions would
help. Even some possible tutorials to chek out would help.

To generate random number integer from set [1, 50] you can use: "number
= rand() % 50 + 1;" (remember to initialise pseudo-random number
generator with for instance srand(time(0))).

To get bucket number you can use "bucket = (number - 1) / 5;" (so in
fact it is better to generate random integer from set [0, 49] using
"number = rand() % 50;" and then calculate bucket number using "bucket =
number / 5;").

Then you increment given bucket, ie.: "buckets[bucket]++". Buckets have
to be zeroed first of course. And when results are ready you print the
results using two nested for loops.

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>---<jid:mina86*chrome.pl>--ooO--(_)--Ooo--
.



Relevant Pages

  • Re: Simple Random Integer Generation
    ... I simply need a function that will generate a random integer between say 1 and 999. ... Its an instance of the RandomGen class just in case ... anyone wants to implement a different random number generator. ... its just like any other language it has to do it in the IO monad. ...
    (comp.lang.functional)
  • Better use of random number genator bits?
    ... If I have a random number generator creating random binary digits, ... and I want to construct a random integer between 0 and say 40, ... Also another way we know is to produce a 226 bit random number but the math ...
    (sci.math)
  • Re: One in a Trillion...!!!
    ... Not in the output of the random number generator before it has been ... congruential generator like the HP has MUST repeat. ... But the most curious thing about this is how the loops tend to have the ... Try extracting two digit numbers from near the middle of the output from ...
    (comp.sys.hp48)
  • Re: random data in structure - checking for no double values
    ... (it is in fact a generator for numbers like in a lotto), ... is there a possibility to circumvent packing an array with the values ... void KnuthShuffle(int n, int* deck) ... generating a random integer between 1 and 45 is better (if ...
    (comp.lang.c)
  • Re: ANN: Generator package version 0.1
    ... loops like foreach require a complete list of values, ... basic generator with use: ... set c [countfrom 10] ...
    (comp.lang.tcl)

Loading