June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,13 @@
function tag(x::Pair, attr::Pair...)
t, b = x
attrstr = join(" $n=\"$p\"" for (n, p) in attr)
return "<$t$attrstr>$b</$t>"
end
colnames = split(",X,Y,Z", ',')
header = join(tag(:th => txt) for txt in colnames) * "\n"
rows = collect(tag(:tr => join(tag(:td => i, :style => "font-weight: bold;") * join(tag(:td => rand(1000:9999)) for j in 1:3))) for i in 1:6)
body = "\n" * join(rows, '\n') * "\n"
table = tag(:table => string('\n', header, body, '\n'), :style => "width: 60%")
println(table)

View file

@ -0,0 +1,11 @@
<table style="width: 60%">
<th></th><th>X</th><th>Y</th><th>Z</th>
<tr><td style="font-weight: bold;">1</td><td>5399</td><td>5770</td><td>3362</td></tr>
<tr><td style="font-weight: bold;">2</td><td>4564</td><td>1577</td><td>5428</td></tr>
<tr><td style="font-weight: bold;">3</td><td>6257</td><td>7290</td><td>6138</td></tr>
<tr><td style="font-weight: bold;">4</td><td>3912</td><td>5163</td><td>2451</td></tr>
<tr><td style="font-weight: bold;">5</td><td>1426</td><td>1874</td><td>3944</td></tr>
<tr><td style="font-weight: bold;">6</td><td>3896</td><td>9827</td><td>7006</td></tr>
</table>

View file

@ -2,18 +2,23 @@ extern crate rand;
use rand::Rng;
fn random_cell() -> usize {
// Anything between 0 and 10000 has 4 digits or less
return rand::thread_rng().gen_range(0, 10000);
fn random_cell<R: Rng>(rng: &mut R) -> u32 {
// Anything between 0 and 10_000 (exclusive) has 4 digits or fewer. Using `gen_range::<u32>`
// is faster for smaller RNGs. Because the parameters are constant, the compiler can do all
// the range construction at compile time, removing the need for
// `rand::distributions::range::Range`
rng.gen_range(0, 10_000)
}
fn main() {
let mut rng = rand::thread_rng(); // Cache the RNG for reuse
println!("<table><thead><tr><th></th><td>X</td><td>Y</td><td>Z</td></tr></thead>");
for row in 0..3 {
let x = random_cell();
let y = random_cell();
let z = random_cell();
let x = random_cell(&mut rng);
let y = random_cell(&mut rng);
let z = random_cell(&mut rng);
println!("<tr><th>{}</th><td>{}</td><td>{}</td><td>{}</td></tr>", row, x, y, z);
}