Modified random distribution: Difference between revisions
Added R: The only solution with a vertical histogram?
ReeceGoding (talk | contribs) (Added R: The only solution with a vertical histogram?) |
|||
Line 757:
0.87, 5422, 1039: ##################################
0.93, 6205, 783: #######################################</pre>
=={{header|R}}==
Although it may not be immediately obvious, both modifier and gen are equivalent to the corresponding functions in the task.
<lang R>library(NostalgiR) #For the textual histogram.
modifier <- function(x) 2*abs(x - 0.5)
gen <- function()
{
repeat
{
random <- runif(2)
if(random[2] < modifier(random[1])) return(random[1])
}
}
data <- replicate(100000, gen())
NostalgiR::nos.hist(data, breaks = 20, pch = "#")</lang>
{{out}}
<pre>> NostalgiR::nos.hist(data, breaks = 20, pch = "#")
10000 +--+---------------------+---------------------+----------------------+---------------------+---------------------+--+
| # |
| # # |
| # # |
| # # # # |
| # # # # |
8000 + # # # # +
| # # # # |
| # # # # # # |
| # # # # # # |
| # # # # # # # # |
F | # # # # # # # # |
r 6000 + # # # # # # # # +
e | # # # # # # # # # # |
q | # # # # # # # # # # |
u | # # # # # # # # # # |
e | # # # # # # # # # # # # |
n 4000 + # # # # # # # # # # # # +
c | # # # # # # # # # # # # # |
y | # # # # # # # # # # # # # # |
| # # # # # # # # # # # # # # |
| # # # # # # # # # # # # # # # |
| # # # # # # # # # # # # # # # # |
2000 + # # # # # # # # # # # # # # # # +
| # # # # # # # # # # # # # # # # # # |
| # # # # # # # # # # # # # # # # # # |
| # # # # # # # # # # # # # # # # # # |
| # # # # # # # # # # # # # # # # # # # # |
| # # # # # # # # # # # # # # # # # # # # |
0 + # # # # # # # # # # # # # # # # # # # # +
+--+---------------------+---------------------+----------------------+---------------------+---------------------+--+
0 0.2 0.4 0.6 0.8 1 </pre>
=={{header|REXX}}==
If a vertical histograph (instead of a <big><big><big><</big></big></big> shaped horizontal histograph) were to be used, it would be a <big><big>V</big></big> shaped.
|