LorumIpsum

Med nedenstående klasse kan du nemt anonymisere en database – dvs. erstatte tekst med Lorum Ipsum og alle tal med randoms. Dette kan være nyttigt til at skabe test eller demo data

Class LorumIpsum
	Private words As Variant
	Private wordCount As double

	Sub New
		words = Split(|a,ac,accumsan,adipiscing,aliquam,aliquet,amet,ante,arcu,at,auctor,augue,aenean,bibendum,blandit,commodo,condimentum,congue,consectetur,consequat,convallis,cubilia,cursus,cras,cum,curabitur,curae;,dapibus,diam,dictum,dictumst,dignissim,dis,dolor,dui,donec,egestas,eget,eleifend,elementum,elit,enim,erat,eros,est,et,eu,euismod,etiam,facilisis,faucibus,felis,fermentum,feugiat,fringilla,fusce,gravida,habitasse,hac,hendrerit,iaculis,id,imperdiet,in,interdum,ipsum,integer,justo,lacinia,lacus,laoreet,lectus,leo,libero,ligula,lobortis,lorem,luctus,magna,magnis,malesuada,massa,mattis,mauris,metus,mi,molestie,mollis,montes,mus,maecenas,morbi,nascetur,natoque,nec,neque,nibh,nisi,nisl,non,nulla,nunc,nam,nullam,odio,orci,ornare,parturient,pellentesque,penatibus,pharetra,placerat,platea,porta,porttitor,posuere,pretium,primis,pulvinar,purus,phasellus,praesent,proin,quam,quis,quisque,rhoncus,ridiculus,risus,rutrum,sagittis,sapien,scelerisque,sed,semper,sem,sit,sociis,sodales,sollicitudin,suscipit,suspendisse,tellus,tempor,tempus,tincidunt,tortor,tristique,turpis,ullamcorper,ultrices,ultricies,urna,ut,varius,vehicula,vel,velit,venenatis,vestibulum,vitae,viverra,volutpat,vulputate,vivamus|, ",")
		wordCount = UBound( words )
		randomize
	End Sub

	Private Function getPrecision( value As Variant ) As Integer
		Dim result As Integer
		result = 0

		Dim s As String
		s = CStr( value )
		If InStr( s, "," ) > 0 Then
			getPrecision = Len( StrRight( s, "," ))
		Else
			While Right( s, 1 )="0" And Len(s ) > 2
				result = result-1
				s = Left( s, Len(s )-1 )
			Wend

			getPrecision = result
		End If
	End Function

	public Function getRandom( min As Double, max As double) As Double
		getRandom = (max-min)* rnd( 1 ) + min
	End Function

	Function randomNum( value As variant ) As Double
		Dim precision As Integer
		precision = getPrecision( value )
		value = value * getRandom( 0.2, 5 )

		randomNum = Round( value, precision )
	End Function

	Function randomString( value As String ) As String
		Dim s As String

		Dim result As Variant
		result = Split( value, " " )

		 Dim uppercase As Boolean
		 uppercase = true
		 Dim i As Integer
		 For i = 0 To UBound( result )
		 	Dim lastChar As String
		 	lastChar = right( result( i ), 1 )
		 	Dim idx As Integer
			 idx = CInt( getRandom( 0, wordCount ))
			result( i ) = words( idx )
			If uppercase Then
				result( i ) = UCase( Left( result( i ),1 )) & Mid( result( i ), 2 )
				uppercase = false
			End If

			Select Case lastchar
			Case ".":
				result( i ) = result( i ) & lastchar
				uppercase = True
			Case ",":
				result( i ) = result( i ) & lastchar
			End Select
		 Next

		 randomString = Join( result, " " )
	End Function
End Class

Links

Skriv et svar

Din e-mailadresse vil ikke blive publiceret. Krævede felter er markeret med *

*