# Kind Of A Rand Number Algorithm...

## Recommended Posts

This is only a little attempt at a rand algorithm..

Here is a little(not good) random number algorithm i made. It generates a number between 0 and 5000

i don't think it will go over 5000.... atleast it should'nt...

```#include <date.au3>
Func _Rand()
\$timer = TimerStart()
\$a = \$timer * 2
\$st = TimerStart ()
\$num = StringLen("" & \$a)
\$b = StringMid(\$a, \$num / 2, \$num / 2)
\$c = StringTrimLeft(\$b, 1)
\$d = StringTrimRight(\$b, 1)
\$e = StringSplit(\$d, "")
\$f = \$e[1]
\$ed = TimerInit()
\$Multiplier = TimerDiff(\$st)
\$z = _NowTime()
\$y = StringSplit(\$z, ":")
If \$y[3] > 30 And \$y[3] < 60 Then
\$y[3] = Sqrt(\$y[3])
EndIf
\$x = \$y[3] * \$f - \$Multiplier
\$num = StringSplit(\$x, "")
\$num2 = \$num[2]
\$num3 = \$num2 * \$y[3]
\$complete = Round(\$num3 * Sqrt(\$x))
\$End = TimerInit()
\$Time = TimerDiff(\$timer)
\$Rand = \$complete * \$Time
\$Rand = Round(\$Rand)
Return \$Rand
EndFunc ;==>_Rand```

ten random number i just now generated from it:

559

454

450

648

548

449

459

469

451

450

Edited by CHRIS95219

##### Share on other sites

What is wrong with the built in 'Random' function?

Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

##### Share on other sites

nothing... i just wanted to take a stab at trying to make my own... it sux. but just wanted to try.

##### Share on other sites

This was my stab at a random number generator.

Based on the state = state * a + b algorithum

```Global \$a, \$b, \$prevstate
Func _RandomInit(\$v1 = @MIN&@HOUR, \$v2 = @WDAY&@SEC)
\$a = \$v1
\$b = \$v2
\$prevstate = 0
EndFunc
Func _RandomNext(\$min, \$max)
\$prevstate = \$prevstate * \$a + \$b
\$prevstate = Int(\$prevstate/(\$max-\$min))
return \$prevstate+\$min
EndFunc```

How to use:

To use a seed (to create a list of numbers that will be the same everytime you use the same seed)

Seeds: 100, 300

_RandomInit(100, 300)

To use random seeds:

_RandomInit()

To Get a pesudoRandom Number

[number from 0 to 100]:

_RandomNext(0, 100)

Only integers.

This was only a stab at it... nothing much...

#)

##### Share on other sites

"cmd /k echo %random%"

That was simple but effective...

#)

##### Share on other sites

```Local \$Seed = Int(InputBox("Enter Seed: "))
Local \$A = Int(Rand(0, 2^32))
Local \$B = Int(Rand(0, 2^32))
Local \$Mod = 512
Local \$Cache = \$Seed
For \$x = 0 To 100
ConsoleWrite(\$A*\$Cache+\$B)%\$Mod)
Next```

I haven't played too much with AU3 code, so that might need to be re-coded

Writing AutoIt scripts since
`_DateAdd("d", -2, _NowCalcDate())`

##### Share on other sites

```Local \$Seed = Int(InputBox("Enter Seed: "))
Local \$A = Int(Rand(0, 2^32))
Local \$B = Int(Rand(0, 2^32))
Local \$Mod = 512
Local \$Cache = \$Seed
For \$x = 0 To 100
ConsoleWrite(\$A*\$Cache+\$B)%\$Mod)
Next```

I haven't played too much with AU3 code, so that might need to be re-coded

? what is Rand()? Edited by CHRIS95219

##### Share on other sites

I belive he means Random().

The correct Version of his Code is:

```Local \$Seed = Int(InputBox("Seed", "Enter Seed:"))
Local \$A = Int(Random(0, 2^32))
Local \$B = Int(Random(0, 2^32))
Local \$Mod = 512
Local \$Cache = \$Seed
For \$x = 0 To 100
ConsoleWrite(Mod((\$A*\$Cache+\$B),\$Mod))
Next```

But I don't understand, why it is supossed to be an Random Algorithm.

1. It uses Random(), ergo you use the Random Algorithm,you want to rebuild, inside the new algorithm

2. When I use \$Seed = 23 I get for example following Returnvalue:

```4834834834834834834834834834834834834834834834834834834834834834834834834834834834834834834834834834

8348348348348348348348348348348348348348348348348348348348348348348348348348348348348348348348348348

3483483483483483483483483483483483483483483483483483483483483483483483483483483483483483483483483483

483```

which is imho not very "random".

Edited by freanir

freanir

##### Share on other sites

I belive he means Random().

The correct Version of his Code is:

```Local \$Seed = Int(InputBox("Seed", "Enter Seed:"))
Local \$A = Int(Random(0, 2^32))
Local \$B = Int(Random(0, 2^32))
Local \$Mod = 512
Local \$Cache = \$Seed
For \$x = 0 To 100
ConsoleWrite(Mod((\$A*\$Cache+\$B),\$Mod))
Next```

But I don't understand, why it is supossed to be an Random Algorithm.

1. It uses Random(), ergo you use the Random Algorithm,you want to rebuild, inside the new algorithm

2. When I use \$Seed = 23 I get for example following Returnvalue:

```4834834834834834834834834834834834834834834834834834834834834834834834834834834834834834834834834834

8348348348348348348348348348348348348348348348348348348348348348348348348348348348348348348348348348

3483483483483483483483483483483483483483483483483483483483483483483483483483483483483483483483483483

483```

which is imho not very "random".

yeah.... if ur making your own algorithm, u can't use someone else's too. lol

##### Share on other sites

\$A and \$B need to be set by the user, as well as \$Seed and \$Mod. It is a simple, psuedo-random number generator. I put the rand in there just to throw out a few numbers, I guess I probably should have put inputboxes there as well...

It is designed to be used more for encryption than it is for a generic random number.

Edited by MSLx Fanboy

Writing AutoIt scripts since
`_DateAdd("d", -2, _NowCalcDate())`

## Create an account

Register a new account

×

• Wiki

• Back

• Git