<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>William Adams' WebLog : A Bit Short</title><link>http://blogs.msdn.com/wadams/archive/tags/A+Bit+Short/default.aspx</link><description>Tags: A Bit Short</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Scheming with Schema</title><link>http://blogs.msdn.com/wadams/archive/2004/02/26/80900.aspx</link><pubDate>Fri, 27 Feb 2004 06:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:80900</guid><dc:creator>wadams</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/wadams/comments/80900.aspx</comments><wfw:commentRss>http://blogs.msdn.com/wadams/commentrss.aspx?PostID=80900</wfw:commentRss><description>&lt;P&gt;Pokemon; Ed, Edd, and Eddy; Masters of the Universe; Zoids.&lt;/P&gt;
&lt;P&gt;These are the cartoons you get to watch, either because you woke up at 6am, or so happen to be watching at 9pm like I am.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Why am I watching TV right now?&amp;nbsp; Because I was typing some schema code while sitting on my bed in my room, and my battery said it was getting low.&amp;nbsp; My laptop's power cord is downstairs plugged in next to the couch in front of the TV, so here I sit and type.&lt;/P&gt;
&lt;P&gt;Laptops are great because they're powerful enough to actually get some programming done these days.&amp;nbsp; I don't have to be sitting at my desk any more.&lt;/P&gt;
&lt;P&gt;Speaking of sitting at my desk, as my laptop sat on my desk last week, I wiped out the various source trees, and internal installations of Visual Studio, and loaded Visual Studio 2003 Professional.&amp;nbsp; I debated a long time between this particular release, and putting the latest Whidbey release on my machine.&amp;nbsp; I ended up with this stock version because it's what everyone in the public has.&amp;nbsp; I want to do some coding samples, and I want those samples to be accessible to more people than Whidbey insiders.&lt;/P&gt;
&lt;P&gt;In our group, we spend most of our time looking forward.&amp;nbsp; VS 2003 represents code that we first released in 2002, which was originally designed in 1999/2000.&amp;nbsp; But, what does it look like?&amp;nbsp; I was part of the team which this stuff was designed.&amp;nbsp; It seemed like it was all so terrific at the time.&lt;/P&gt;
&lt;P&gt;The two most primary design centers were XmlReader and XmlNavigator.&amp;nbsp; Other pieces of the puzzle include DOM, XSLTTransform and the like.&amp;nbsp; XmlSchema came later in the cycle as the XML Schema standard was ratified.&amp;nbsp; That's a whole other story that I'll have to relate some time.&lt;/P&gt;
&lt;P&gt;What I'm looking for in particular is how to use the XmlSchema Object.&amp;nbsp; I'm mainly concerned with how I can turn my newly inferred book schemas into working program code for a simple librarian application.&amp;nbsp; There's plenty of fertile ground for this application.&amp;nbsp; I'll let you know how it goes.&lt;/P&gt;
&lt;P&gt;In the meanwhile, I was actually trying to use the Schema Object Model, and all I can say is... I'm sorry.&lt;/P&gt;
&lt;P&gt;The conclusion I've come to is, using the C# editor to create schemas is not quite the right tool.&lt;/P&gt;
&lt;P&gt;What I mean is this.&amp;nbsp; When your schema looks something like this:&lt;/P&gt;&lt;PRE class=code&gt;&amp;lt;?xml version="1.0"?&amp;gt;
&amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;
  &amp;lt;xs:group name="testGroup"&amp;gt;
  &amp;lt;xs:choice&amp;gt;
    &amp;lt;xs:any namespace="##any"/&amp;gt;
  &amp;lt;/xs:choice&amp;gt;
  &amp;lt;/xs:group&amp;gt;
  &amp;lt;xs:element name="myElement" &amp;gt;
  &amp;lt;xs:complexType&amp;gt;
    &amp;lt;xs:choice maxOccurs="unbounded"&amp;gt;
      &amp;lt;xs:group ref="testGroup" /&amp;gt;
    &amp;lt;/xs:choice&amp;gt;
  &amp;lt;/xs:complexType&amp;gt;
  &amp;lt;/xs:element&amp;gt;
&amp;lt;/xs:schema&amp;gt;&lt;/PRE&gt;
&lt;P&gt;It's probably easier to write the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string xsd = "example.xsd";&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FileStream fs;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; XmlSchema schema;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fs = new FileStream(xsd, FileMode.Open);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; schema = XmlSchema.Read(fs, new ValidationEventHandler(ShowCompileError));&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; schema.Compile(new ValidationEventHandler(ShowCompileError));&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;In this case, Notepad has been used as the schema editor, and C# simply loads the result.&amp;nbsp; To create this schema programatically is a lot more involved, and not really that fun.&amp;nbsp; That method is good for tools that are generating schema on the fly.&amp;nbsp; It's not really the interface that I would recommend for programmers who are consuming schemas.&lt;/P&gt;
&lt;P&gt;So, maybe it's not that bad.&amp;nbsp; You don't have to use the API to create the schemas, but what about reading it?&lt;/P&gt;
&lt;P&gt;Wha?&amp;nbsp; Is that Samurai Jack?&amp;nbsp; Nope, X-Men.&amp;nbsp; Sorry, gotta go!&lt;/P&gt;
&lt;P&gt;I'll get back to you.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=80900" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/wadams/archive/tags/A+Bit+Short/default.aspx">A Bit Short</category></item><item><title>Posting pictures probably presents problems</title><link>http://blogs.msdn.com/wadams/archive/2004/02/19/76386.aspx</link><pubDate>Thu, 19 Feb 2004 17:19:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:76386</guid><dc:creator>wadams</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/wadams/comments/76386.aspx</comments><wfw:commentRss>http://blogs.msdn.com/wadams/commentrss.aspx?PostID=76386</wfw:commentRss><description>So, I removed them.&amp;nbsp; I'll have to find a better location than MSN to put them so that I can link to them without causing problems.&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=76386" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/wadams/archive/tags/A+Bit+Short/default.aspx">A Bit Short</category></item><item><title>More random thoughts</title><link>http://blogs.msdn.com/wadams/archive/2004/02/17/75338.aspx</link><pubDate>Wed, 18 Feb 2004 07:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:75338</guid><dc:creator>wadams</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/wadams/comments/75338.aspx</comments><wfw:commentRss>http://blogs.msdn.com/wadams/commentrss.aspx?PostID=75338</wfw:commentRss><description>&lt;P&gt;As I was contemplating de treasuring various of my computer books last night, I began to get nostalgic, and I suffered a bit of panic.&amp;nbsp; What if what I wanted was NOT available on the internet?&amp;nbsp; So, I went look.&lt;/P&gt;
&lt;P&gt;A very long time ago, I compiled a set of C++ routines and classes that were rather esoteric in nature.&amp;nbsp; You know, the typical library of sort, search, containers, random number generators and the like.&amp;nbsp; I thought for sure I had the library on disk somewhere.&amp;nbsp; I did, but it was formatted as a BFS filesystem (BeOS file system).&amp;nbsp; So, until I get my BeBox plugged in again, I can't really access that disk.&amp;nbsp; That's another story.&lt;/P&gt;
&lt;P&gt;I thought I remembered the name, and I'm pretty sure I know my own name, so I went to my little Google search bar and typed in &amp;#8220;William Adams bebits ftp&amp;#8221;.&amp;nbsp; After some grubbing around, I found it here:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://linux.inf.elte.hu/ftp/beos/development/samples/support_kit/obsolete/bebits.zip"&gt;http://linux.inf.elte.hu/ftp/beos/development/samples/support_kit/obsolete/bebits.zip&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;It's taylored for the BeOS, which is extinct, but only for the thread and spinlock classes.&amp;nbsp; The rest is fairly generic.&amp;nbsp; It might even be interesting to resurrect it as a C# library, but I think that will largely be covered by generics in Whidbey.&lt;/P&gt;
&lt;P&gt;Looking back at that library is interesting to me because it reminds me of the different design choices, constraints, and assumptions I was operating under at the time.&amp;nbsp; Things like, C++ compilers did not have reliable template implementations, or STL was not quite standard as yet.&amp;nbsp; Things I wouldn't think about today with the far superior MS C++ implementation.&amp;nbsp; But, they were my assumptions at the time.&lt;/P&gt;
&lt;P&gt;I looked at the random number generator that I had in there.&amp;nbsp; Then I thought, &amp;#8220;where did I get that code?&amp;#8221;.&amp;nbsp; Digging back through my library, I remembered that it came from this book: Data structures and problem solving in C++&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;FONT color=#800080&gt;&lt;A href="http://www.cs.fiu.edu/~weiss/#adspc++2"&gt;http://www.cs.fiu.edu/~weiss/#adspc++2&lt;/A&gt;&lt;/FONT&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;That book sells for almost $100 in its second edition.&amp;nbsp; How much will I get for my first edition copy?&amp;nbsp; Probably about $3 at the used book store.&lt;/P&gt;
&lt;P&gt;But, as I had hoped, the source code from the book can be found here:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.cs.fiu.edu/~weiss/adspc++2/code/Random.cpp"&gt;http://www.cs.fiu.edu/~weiss/adspc++2/code/Random.cpp&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;So, I can safely detreasure this book from my library, as painful as it might be.&amp;nbsp; By the way, this particular implementation of a LCG RNG is pretty good because it has a period of 2(32)-1, and it visits all of the numbers.&amp;nbsp; See if your local random number generator does as good, you may or may not be impressed by what you find.&lt;/P&gt;
&lt;P&gt;Looking at the stack of books at my feet, I see a lot of history.&amp;nbsp; I also see history being digitized in the age of the internet.&amp;nbsp; Progress is informed by look backward, but is only made safely by looking forward.&amp;nbsp; I will probably detreasure these classics, but I will probably keep the Knuth book for old time's sake.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;I did go looking into a few plastic storage boxes I have.&amp;nbsp; I found the entire series of Commodore PET user's club magazines from volume 1, issue 1 onward!&amp;nbsp; That represents magazines that are about 25 years old, and the oldest computer magazines in my library.&amp;nbsp; I can't detreasure them because they'd have zero 'value' today.&amp;nbsp; I think they're either headed for eBay, the Boston Computer Society, or the Smithsonian.&amp;nbsp; Who knows, perhaps I'll preserve them for my daughter so she can dispose of them when I'm old and gray.&lt;/P&gt;
&lt;P&gt;For Arpan: To 'Osborne' your product, look here: &lt;A href="http://oldcomputers.net/osborne.html"&gt;http://oldcomputers.net/osborne.html&lt;/A&gt;&amp;nbsp;at the bottom where it talks about the Executive and Vixen releases.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=75338" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/wadams/archive/tags/A+Bit+Short/default.aspx">A Bit Short</category></item><item><title>Random What?  Mersenne who?</title><link>http://blogs.msdn.com/wadams/archive/2004/02/16/74607.aspx</link><pubDate>Tue, 17 Feb 2004 07:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:74607</guid><dc:creator>wadams</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/wadams/comments/74607.aspx</comments><wfw:commentRss>http://blogs.msdn.com/wadams/commentrss.aspx?PostID=74607</wfw:commentRss><description>&lt;P&gt;What do these books have in common?&lt;/P&gt;
&lt;P&gt;CRC Standard Mathematical Tables and Formulae, Numerical Recipes in C, Seminumerical Algorithms, Applied Cryptography, The Twofish Encryption Algorithm&lt;/P&gt;
&lt;P&gt;For starters, they are all published earlier than 1999, mostly before 1996, and in one case, 1969.&amp;nbsp; They all cost about $50 apiece.&amp;nbsp; They all have information that was probably at one point or another classified as munitions by the US government.&amp;nbsp; In my computing history, they have all led to my understanding of encryption, random numbers, and other esoteric subjects required to do some basic computing tasks.&lt;/P&gt;
&lt;P&gt;Why do I look at them now?&amp;nbsp; Well, this is one of those cases where all the information they contain can be found on the internet in one form or another.&amp;nbsp; So, it's time to de Treasure them.&amp;nbsp; But, before they go, I thought I'd look at some of the bookmarks that I had made and see what I was interested in almost 10 years ago.&lt;/P&gt;
&lt;P&gt;From the CRC, I find a bookmark on the page headed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 7.5 RANDOM NUMBER GENERATION&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; 7.5.1 METHODS OF PSEURANDOM NUMBER GENERATION&lt;/P&gt;
&lt;P&gt;Linear Congruential generators.&lt;/P&gt;
&lt;P&gt;Turns out, you can generate pseudo random numbers by a simple formula.&amp;nbsp; Pseudo random because they're not random at all.&amp;nbsp; You can predict exactly what the next number will be based on the current state of the calculation, and the initial state of the calculation.&lt;/P&gt;
&lt;P&gt;Xn = aXn-1 + b (mod M)&lt;/P&gt;
&lt;P&gt;That is, a 'random' number Xn can be generated by taking Xn -1, multiplying by 'a', adding 'b' and modulus 'M'.&amp;nbsp; It works out nicely because it's a simple multiplication, and add, and some other little thing at the end.&amp;nbsp; Really fast stuff.&amp;nbsp; Depending on what numbers you pick for a, b, M , and the initial seed, you can generate these numbers rippin fast on modern computing hardware.&lt;/P&gt;
&lt;P&gt;What's a Mersenne prime?&amp;nbsp; I don't know, I'm sure you can look it up on the internet.&amp;nbsp; It turns out that if you use one of these as the 'M', you get really fast computations.&lt;/P&gt;
&lt;P&gt;One concern with LCG RNGs (Linear Congruential Random Number Generators) is the periodicity.&amp;nbsp; That is, how many times can you generate a number before the sequence begins to repeat itself?&amp;nbsp; The trick is in the numbers you choose.&lt;/P&gt;
&lt;P&gt;There are plenty of tables for what a, b, and M should be&lt;/P&gt;
&lt;P&gt;a&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; M&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Source&lt;/P&gt;
&lt;P&gt;7(5)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2(31)-1&amp;nbsp;&amp;nbsp;&amp;nbsp; Park-Miller&lt;/P&gt;
&lt;P&gt;131&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2(35)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Neave&lt;/P&gt;
&lt;P&gt;16333&amp;nbsp;&amp;nbsp; 25887&amp;nbsp;&amp;nbsp;&amp;nbsp; 2(15)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Oakenfull&lt;/P&gt;
&lt;P&gt;3432&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6789&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9973&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Oakenfull&lt;/P&gt;
&lt;P&gt;171&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;30269&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Wichman-Hill&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For those who are in the know, I'm sure these names mean much, and a hush goes over the audience when they speak.&amp;nbsp; For most of us though, the intricacies of LCG constants are lost in the bowels of the rand() function.&amp;nbsp; Most people neither know, nor care about the details.&amp;nbsp; And that my friends is the beginning of all our troubles with writing secure software.&lt;/P&gt;
&lt;P&gt;What about shift register generators, Lagged-Fibonacci generators, and chained LCGs?&amp;nbsp; What kind of random numbers are you consuming in your applications?&amp;nbsp; Do you care about the distribution of the lower bits?&amp;nbsp; Do you care that your numbers may overflow before the modulus?&amp;nbsp; Do you care that you are losing some precision when you're flipping between int and float?&lt;/P&gt;
&lt;P&gt;These are little tidbits from the CRC.&amp;nbsp; A book chock full of tables, formulas, and the like.&amp;nbsp; I used the CRC when I was in high school to look up log tables.&amp;nbsp; And I'm sure it's been in existance in various forms for a couple hundred years before that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Donald Knuth goes over the top in &amp;#8220;Seminumerical Algorithms&amp;#8221;.&amp;nbsp; Knuth spends an unprecedented 177 pages on the subject of random numbers, random sequences, and anything esoteric with the word 'random' in it.&amp;nbsp; Can you believe it?&amp;nbsp; 177 pages?&amp;nbsp; Surely the spec, docs, code, and tests for the typical rand() function do not take up that much space.&amp;nbsp; I'd guess they typically take up no more than two pages worth of text layed end to end.&lt;/P&gt;
&lt;P&gt;What's the point?&amp;nbsp; I don't know, I guess I'm just being a little random.&amp;nbsp; How random&amp;nbsp;you can't possibly know unless you understand where I started, and under what conditions I change the subject.&lt;/P&gt;
&lt;P&gt;As I de treasure these books, I can't help but think that most programmers using modern programming languages today, aren't likely to amass such a library, nor understand the esoteric little pieces embodied in the deep literature.&amp;nbsp; Maybe we've gone beyond the point of having to care about such things.&amp;nbsp; To a certain extent, this is true.&amp;nbsp; The general computing public does not need to care about the multipliers that are used in the LCG found deep within our rand() implementation.&amp;nbsp; But, I hope the systems programmer who wrote that code sure understood what they were doing, and I hope they didn't de treasure their library of knowledge too soon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=74607" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/wadams/archive/tags/A+Bit+Short/default.aspx">A Bit Short</category></item></channel></rss>