1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

I need an article spinner code that have a different seed every time.

Discussion in 'Visual Basic .NET' started by dragonrage01, May 12, 2013.

  1. dragonrage01

    dragonrage01 Power Member

    Joined:
    May 19, 2011
    Messages:
    674
    Likes Received:
    155
    Can anyone help me please. I have tried most of the spinner codes in this section but none works for me.
    For example when I have {pretty|beautiful|gorgeous}. I put them in lots of paragraphs, I end up getting the same spin every time.
    I mean if the spinner picks "pretty" in one paragraph, all paragraph will have "pretty" also.
    I want something more random. Like if one paragraph has "pretty", the other paragraphs can be "pretty", or "beautiful" or "gorgeous".

    Thanks for any help.
     
  2. frankweerasinghe

    frankweerasinghe Regular Member

    Joined:
    Jun 6, 2011
    Messages:
    434
    Likes Received:
    393
    Location:
    Colombo, Sri Lanka
    Code:
    Private Function Spinner(ByVal mstr As String) As String
            Dim returnword As String
            Dim arrSplit As String()
            Dim cnt As Integer = 0
            Dim rdm As New Random()
            While Regex.IsMatch(mstr, "\{")
                Dim innerspin As String = mstr.Split("{"c)((mstr.Split("{"c).Length) - 1)
                Dim tospin As String = Regex.Match(innerspin, "[\s\S]*?(?=\})").Value
    
    
                arrSplit = tospin.Split("|"c)
                returnword = arrSplit(rdm.[Next](0, arrSplit.Length))
                cnt += 1
                ' Console.WriteLine(cnt)
    
    
                mstr = Regex.Replace(mstr, "\{" & Regex.Escape(tospin) & "\}", returnword)
            End While
            Return mstr
        End Function
    
    How to use this...

    Code:
    Spinner("{your|ur} spintaxed {text|words}")
     
    • Thanks Thanks x 1
  3. dragonrage01

    dragonrage01 Power Member

    Joined:
    May 19, 2011
    Messages:
    674
    Likes Received:
    155
    I tried it and it is not good but thanks for trying.
    I tested it with.

    Code:
    TextBox1.Text = "{1|2|3|4|5|6|7|8|9|0}" + "{1|2|3|4|5|6|7|8|9|0}" + "{1|2|3|4|5|6|7|8|9|0}" + vbCrLf
    TextBox1.Text = Spinner(TextBox1.Text)
    All three outputs were the same. It has to be different like a different seed everytime.
    The spinner should be able to pass this test at the bottom.
    Code:
    TextBox1.Text = "{1|2|3|4|5|6|7|8|9|0}" + "{1|2|3|4|5|6|7|8|9|0}" + "{1|2|3|4|5|6|7|8|9|0}" + vbCrLf
    TextBox1.Text = Spinner(TextBox1.Text)
    TextBox1.Text = TextBox1.Text + "{1|2|3|4|5|6|7|8|9|0}" + "{1|2|3|4|5|6|7|8|9|0}" + "{1|2|3|4|5|6|7|8|9|0}" + vbCrLf
    TextBox1.Text = Spinner(TextBox1.Text)
    

    The output should be more random like
    349
    588
    or
    482
    293

    AND NOT
    444
    444

    AND NOT
    285
    285

    For practical application the sentence will be like:
    She is very {pretty|beautiful|gorgeous}. The place she lives in is {pretty|beautiful|gorgeous}. I wonder if her sister is {pretty|beautiful|gorgeous}?
    Your code will return.
    She is very pretty. The place she lives in is pretty. I wonder if her sister is pretty?
     
    Last edited: Jun 7, 2013
  4. awsomnick1

    awsomnick1 BANNED BANNED

    Joined:
    Feb 8, 2010
    Messages:
    539
    Likes Received:
    154

    Have fun with this, rand just needs to be declared as new each time :)
     
    • Thanks Thanks x 1
  5. dragonrage01

    dragonrage01 Power Member

    Joined:
    May 19, 2011
    Messages:
    674
    Likes Received:
    155
    It didn't work. When I ran it, I got

    Code:
    She is very gorgeous. The place she lives in is gorgeous. I wonder if her sister is gorgeous.999
    When I used this
    Code:
    [COLOR=#FFFFCC]TextBox1.Text = "{1|2|3|4|5|6|7|8|9|0}" + "{1|2|3|4|5|6|7|8|9|0}" + "{1|2|3|4|5|6|7|8|9|0}" + vbCrLf[/COLOR]
    TextBox1.Text = Spinner(TextBox1.Text)TextBox1.Text = TextBox1.Text + "{1|2|3|4|5|6|7|8|9|0}" + "{1|2|3|4|5|6|7|8|9|0}" + "{1|2|3|4|5|6|7|8|9|0}" + vbCrLf
    TextBox1.Text = Spinner(TextBox1.Text)
    I got
    333
    333

    which is not good.
     
  6. r000k

    r000k Registered Member

    Joined:
    Jan 10, 2013
    Messages:
    66
    Likes Received:
    30
    Code:
    
    Dim _items() As String
    
    Function GetRandomItem(ByVal m As Match) As String
            _items = Split(m.Groups(1).Value, "|")
            Return _items(Rnd() * (UBound(_items) + 1))
    End Function
    
    Function Spin(ByVal sInput As String) As String
            Dim r As Long = 0, l As Long = 0
            Dim pattern As String = "\{(/?[^\{}]+)\}"
            Do
                r = InStr(l, sInput, "}", CompareMethod.Binary)
                l = InStrRev(sInput, "{", r - 1, CompareMethod.Binary)
    
                If r = 0 Or l = 0 Then Exit Do
    
                sInput = Regex.Replace(sInput, pattern, AddressOf GetRandomItem)
            Loop
    
            Return sInput.Substring(1)
    End Function
    
    use it like textbox1.text = Spin("{1|2|3|4|5|6|7|8|9|0}" + "{1|2|3|4|5|6|7|8|9|0}" + "{1|2|3|4|5|6|7|8|9|0}")
    
     
    • Thanks Thanks x 1
  7. dragonrage01

    dragonrage01 Power Member

    Joined:
    May 19, 2011
    Messages:
    674
    Likes Received:
    155
    Thanks but it didn't work for me. It didn't spin at all. Are you sure about the code?

    The output for me was
    {1|2|3|4|5|6|7|8|9|0}{1|2|3|4|5|6|7|8|9|0}{1|2|3|4|5|6|7|8|9|0}

    and I used

    textbox1.text = Spin("{1|2|3|4|5|6|7|8|9|0}" + "{1|2|3|4|5|6|7|8|9|0}" + "{1|2|3|4|5|6|7|8|9|0}")