16 lines
515 B
Plaintext
16 lines
515 B
Plaintext
ClearAll[Modifier, CreateRandomNumber]
|
|
Modifier[x_] := If[x < 0.5, 2 (0.5 - x), 2 (x - 0.5)]
|
|
CreateRandomNumber[] := Module[{r1, r2, done = True},
|
|
While[done,
|
|
r1 = RandomReal[];
|
|
r2 = RandomReal[];
|
|
If[r2 < Modifier[r1],
|
|
Return[r1];
|
|
done = False
|
|
]
|
|
]
|
|
]
|
|
numbers = Table[CreateRandomNumber[], 100000];
|
|
{bins, counts} = HistogramList[numbers, {0, 1, 0.05}, "PDF"];
|
|
Grid[MapThread[{#1, " - ", StringJoin@ConstantArray["X", Round[20 #2]]} &, {Partition[bins, 2, 1], counts}], Alignment -> Left]
|