Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Thomas Kahn 602 posts 506 karma points
    Nov 15, 2010 @ 16:16
    Thomas Kahn
    0

    Is there a bug in umbraco.library:GetRandom?

    Hi!

    I'm using umbraco.library:GetRandom to get a random number, but it doesn't quite behave like I expect it to. In my XSLT I've added a C# script that looks like this:

    <msxml:script implements-prefix="random" language="C#">
        <msxml:assembly name="umbraco"/>
        <msxml:using namespace="umbraco"/>
        <![CDATA[
        public int GetRandom(int minValue, int maxValue)
        {
            return umbraco.library.GetRandom().Next(minValue, maxValue);
        }
        ]]>
    </msxml:script>

    It comes from this thread where Thomas Höhler has a good random example.

    As you can see it uses umbraco.library.GetRandom() to get a random number. In my XSLT-code I call it like this:

    <xsl:variable name="randomNumber" select="random:GetRandom(1,2)"/>

    Now I expect it to return a value that is either 1 or 2 when I reload the page. The problem is that it returns only the number 1. If i alter the code to:

    <xsl:variable name="randomNumber" select="random:GetRandom(1,3)"/>

    ...it returns a number that is either 1 or 2. Is this a bug or does this mean that the maxValue is not actually the max value that it will return but rather the the max value that it won't return.

    Can anyone else confirm this? Is it a bug or a feature or am I just using the method wrong?

    Any pointers are greatly appreciated!

    /Thomas Kahn

Please Sign in or register to post replies

Write your reply to:

Draft