Use rand in c to generate a sequence of random numbers that go from 3 to 3?

1

Is there a simple way in which using rand (without using other functions) can generate random numbers between 45 and 75 (inclusive) and that these are 45,48,51,54,57,60,63,66,69,72,75 (that is, go from 3 to 3)?

I know how to perform the interval but not the sequence. The interval would be

  

45+ (rand ()% 33)

But I should add something to perform the sequence. Sorry if the question is very basic.

    
asked by Emmaaaaa 26.01.2018 в 14:09
source

1 answer

6

It simply generates random numbers between 0 and 10 . The result is multiplied by 3 and you add 45 :

| Número | × 3 | + 45 |
+--------+-----+------+
|      0 |   0 |   45 |
|      1 |   3 |   48 |
|      2 |   6 |   51 |
|      3 |   9 |   54 |
|      4 |  12 |   57 |
|      5 |  15 |   60 |
|      6 |  18 |   63 |
|      7 |  21 |   66 |
|      8 |  24 |   69 |
|      9 |  27 |   72 |
|     10 |  30 |   75 |
    
answered by 29.01.2018 / 12:14
source