[R] generate random numbers for lotteries

jim holtman jholtman at gmail.com
Sun Apr 29 23:16:44 CEST 2012


I would assume that you would use 'sample' to draw the numbers:

> sample(0:10,60,TRUE)
 [1]  2  3  1  2  9  2  2  0  3
[10]  0  4  2  3  9  7  3 10  9
[19]  8  5  8  7  6  3 10  0  6
[28]  8 10  6  3  3  2  7  0  0
[37]  1  4  8  2 10  2  0  7  9
[46]  9  9  7  9  6 10  1  1  6
[55]  1  8  3  8  2  6



On Sun, Apr 29, 2012 at 4:38 PM, Vale Fara <valef78 at gmail.com> wrote:
> Hi,
>
> thank you both for your replies, I really appreciate it!
>
> To Mike: yes, random integers. Can I use the function round() as in
> the example with 5 random numbers below?
>
> To Billy: for the second part I got an error, but it may be that I
> didn't properly set "i"...?
> Here is the R output:
> x <- runif(60 , 0 , 10) # 60 numbers from 0 to 10
>> x
>  [1] 3.29208009 8.62643979 3.40762875 0.35224714 6.78760173 4.72160818 etc
> y<-  runif(60, 15 , 25) # same as above , from 15 to 25
>> y
>  [1] 18.48391 24.44361 23.20955 16.61257 23.06074 17.71158 23.67585 19.31675 etc
> i <- 12
>> i
> [1] 12
>> for( i in 1:length(x)) {
> + z = x[i] + y[i]
> + return z}
> Errore: unexpected symbol in:
> "z = x[i] + y[i]
> return z"
>
> To all: I attach an example with only 5 random numbers
>
> step 1. random number generation
> x <- round(runif(5 , 0 , 10) )
> < x
>  [1]  2 1  0  6  8
> y <- round(runif(5 , 15 , 25) )
>> y
>  [1] 21 24 22 22 19
>
> step2. matching of numbers from x and y to create lotteries
> lottery 1: 2$ with 50% probability vs.  21$ with 50% of probability
> (Expected value: 2*0.5+21*0.5=11.5)
> lottery 2: 1$ with 50% probability vs.  24$ with 50% of probability
> (Expected value: 1*0.5+24*0.5=12.5)
> lottery 3: 0$ with 50% probability vs.  22$ with 50% of probability
> (Expected value: 0*0.5+22*0.5=11)
> lottery 4: 6$ with 50% probability vs.  22$ with 50% of probability
> (Expected value: 6*0.5+22*0.5=14)
> lottery 5: 8$ with 50% probability vs.  19$ with 50% of probability
> (Expected value: 8*0.5+19*0.5=13.5)
>
> step 3. Form step 2, I know that the min EV of these lotteries is 11
> and the max EV is 14.
> The difference is: max EV - min EV = 3.
> I need a difference of 5
>
> How to do this?
>
> Valeria
>
>
>
> 2012/4/29 billy am <wickedpuppy at gmail.com>:
>> Interesting set of question.. I am completely new to R but let me try my
>> luck.
>>
>> Random number in R
>>
>> x <- runif(60 , 0 , 10) # 60 numbers from 0 to 10
>> y<-  runif(60, 15 , 25) # same as above , from 15 to 25
>>
>> The second part though. Do you mean ,
>>
>> for( i in 1:length(x)) {
>> z = x[i] + y[i]
>> return z
>> }
>>
>> something like that? No idea about the third part though.
>>
>> regards
>> Billy
>>
>> On Sun, Apr 29, 2012 at 9:29 AM, Mike Miller <mbmiller+l at gmail.com> wrote:
>>>
>>> On Fri, 27 Apr 2012, Vale Fara wrote:
>>>
>>>> I am working with lotteries and I need to generate two sets of uniform
>>>> random numbers.
>>>>
>>>> Requirements:
>>>> 1) each set has 60 random numbers
>>>
>>>
>>> random integers?
>>>
>>>
>>>> 2) random numbers in the first set are taken from an interval (0-10),
>>>> whereas numbers in the second set are taken from a higher interval
>>>> (15-25)
>>>
>>>
>>> Depends on if you mean integers.  R has functions.  Here's one:
>>>
>>> http://www.astrostatistics.psu.edu/su07/R/html/stats/html/Uniform.html
>>>
>>>
>>>
>>>> 3) numbers generated in the first set should be matched to numbers in
>>>> the second set (row by row) so that the expected value of each couple
>>>> of random numbers (i.e. of each lottery) is around to a given value
>>>> (12.5 +/- 5, where 12.5 is the median value of the interval extremes).
>>>
>>>
>>> Do you mean that the mean for the pair of numbers must be between 7.5 and
>>> 17.5, inclusive?  That means the sum must be from 15 to 35.  Well, you are
>>> in luck because if you make the numbers as you suggested above, that will
>>> happen -- you don't have to do anything special to make it happen.
>>>
>>>
>>>
>>>> For the computation of the expected value, the probabilities in each
>>>> lottery are ½ and ½.
>>>
>>>
>>> For what outcome?  You lost me.
>>>
>>>
>>>
>>>> How do this? Any help given would be greatly appreciated.
>>>
>>>
>>> I hope that helps.
>>>
>>> Mike
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>>
>> --
>> http://use-r.com  - R Statistics Scripting & Programming Language Online
>> Community Home
>> http://bam.domainpool.com - Domains For Sale
>> http://SQLHack.net - Tech Blog/Tutorials
>>
>> ------------------------------------------------------------------------------------
>>
>> MCSA (Security) , MCSA , CCNA , LPIC - Lvl 1 , Security+ ,  Network+ , A+
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.



More information about the R-help mailing list