c# - in random number generator -
c# - in random number generator -
for reason, code works fine when don't utilize seed in random class, if seek utilize datetime.now more random number, stackoverflowexception! class simple. tell me i'm doing wrong here? see makeuniquefilename.
public class temputil { private int strcmp(string s1, string s2) { seek { (int = 0; < s1.length; i++) if (s1[i] != s2[i]) homecoming 0; homecoming 1; } grab (indexoutofrangeexception) { homecoming 0; } } private int uniqueness(object randomobj) { switch (randomobj.tostring()) { case "system.object": case "system.string": homecoming randomobj.tostring()[0]; case "system.int32": homecoming int.parse(randomobj.tostring()); case "system.boolean": homecoming strcmp(randomobj.tostring(), "true"); default: homecoming uniqueness(randomobj.tostring()); } } public string makeuniquefilename() { homecoming "c:\\windows\\temp\\" + new random(uniqueness(datetime.now)).nextdouble() + ".tmp"; } }
in short:
it should
switch (randomobj.gettype().tostring()) instead of
switch (randomobj.tostring()) but isn't clever.
c# random stack-overflow
Comments
Post a Comment