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

dragonrage01

Power Member
Joined
May 19, 2011
Messages
674
Reaction score
159
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.
 
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}")
 
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:
Code:
Private Function Spinner(ByVal mstr As String) As String
        Dim returnword As String
        Dim arrSplit As String()
        Dim cnt As Integer = 0
       
        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

          [B][COLOR=#ff0000]  Dim rdm As New Random()[/COLOR][/B]
            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}")


Have fun with this, rand just needs to be declared as new each time :)
 
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.
 
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 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}")
 
Back
Top