Skip to content

Commit 23403bd

Browse files
committed
---
yaml --- r: 6953 b: refs/heads/master c: af41564 h: refs/heads/master i: 6951: 25ded9a v: v3
1 parent 4f2ccf6 commit 23403bd

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 5d84652f511d68f401493284c82525cdabe2fafb
2+
refs/heads/master: af415647475b30e296ce7ef26abb9ec63d2458e6

trunk/src/libstd/rand.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ type rng = obj {
3939
Return a random string composed of A-Z, a-z, 0-9.
4040
*/
4141
fn gen_str(len: uint) -> str;
42+
43+
/*
44+
Method: gen_bytes
45+
46+
Return a random byte string.
47+
*/
48+
fn gen_bytes(len: uint) -> [u8];
4249
};
4350

4451
resource rand_res(c: rustrt::rctx) { rustrt::rand_free(c); }
@@ -74,6 +81,16 @@ fn mk_rng() -> rng {
7481
}
7582
s
7683
}
84+
fn gen_bytes(len: uint) -> [u8] {
85+
let v = [];
86+
let i = 0u;
87+
while i < len {
88+
let n = rustrt::rand_next(**c) as uint;
89+
v += [(n % (u8::max_value as uint)) as u8];
90+
i += 1u;
91+
}
92+
v
93+
}
7794
}
7895
ret rt_rng(@rand_res(rustrt::rand_new()));
7996
}

0 commit comments

Comments
 (0)