I am trying to generate a random number from 1e-9 to 1e9. The very naive idea is to generate a sequence from 1 to 1e18, then divide by 1e9. as following. but seems not working.
set.seed(100)
rand <- sort(runif(10000, min =1, max= 1e18))/1e9
result <- sample(rand, 1)
min(rand)
max(rand)
# result 664426274
# min(rand) 199051.1
# max(rand) 999853646
rand %>% ecdf() %>% plot
log(rand) %>% ecdf() %>% plot
the min number is much higher than I expect. Besdies, I checked the plot with ecdf. it seems the numbers below 1 is quite limited. How can I generate a uniform distributed sequence?
ps, what if I generate the sequence with 2 steps?
rand2 <- c(runif(5000)/1e9, runif(5000, min = 1, max = 1e9))
it goes in this way.
rand2 %>% ecdf() %>% plot log(rand2) %>% ecdf() %>% plot
Please advise.
update:
I am doing a classification of 2 classes. I am trying to decide where the threshold located to best accommendate to the result. There shall be a value to generate most likely to come close to the label. Hopefully I am right.
vA vZ AZ UID
1: 1.000000000 2.416923e-09 A trosjt
2: 0.994873822 5.126146e-03 A trosjt
3: 0.971833944 2.816611e-02 A trosjt
4: 0.988399029 1.160089e-02 A trosjt
5: 0.001416997 9.985831e-01 A trosjt
....
63424: 0.965989590 3.401040e-02 Z cdhglk
63425: 0.798483849 2.015162e-01 Z cdhglk
63426: 0.986248076 1.375197e-02 Z cdhglk
63427: 0.947122157 5.287788e-02 Z cdhglk
63428: 0.948470414 5.152961e-02 Z cdhglk
In the second approach, I am imagining that I have a sequence evenly(hopefully) distribyuted. Once I get a reasonable range, I will regenerate the sequence, and redo again, hope gradually I will be close enough to the acceptable answer.


Aucun commentaire:
Enregistrer un commentaire