Tomaz.tsql

January 2012 - Posts

simple word randomization based on dictionary

Based on list of words, one can randomize the letters in the word using simple cross apply.

 

;with dictionary as
(
    select 'soundgarden' as  word union all
    select 'impossible' as word union all
    select 'apple' as word union all
    select 'microsoft' as word union all
    select 'mices' as word union all
    select 'ITCrowds' as word
)
select
     t1.word
    ,x.n
        from dictionary as t1
    cross apply (
                    select
                            substring(t1.word,sv.number,1)
                        from   
                                master..spt_values as sv
                        where
                            sv.type = 'P'
                        and sv.number between 1 and 30 -- max word length
                        order by (select (abs(checksum(newid())))%1000) desc
                        for xml path('')
                ) as x(n)