Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

ActualRand()

Hello fellow coders of HF!

In my couple years of coding I've come to realize that the default "Random", doesn't return a random. It tends to return very close values if executed within short time periods. I decided to take action, and make a truly 100% random Random function. Me and my friend (mostly him) came up with this algorithm.

Pictures are provided for everyone

If you are L33t or Ub3r then PM me for straight source ( name the PM Random)


[Image: 610b747739c62d1353b7c17a2c43e86e.png]

Please leave feedback, it is much appreciated. 🤝


EDIT:: So you guys said it was stolen, I didn't know. As I said he did a lot of the work, I didn't know that he took it from a site. I apologize.
You didn't do this: http://www.vbforums.com/showthread.php?3...-Generator.
The code from the link above (Attached Files):
Code
Public Class TrueRandom
    ''''''
    ''Use this class at will      ''''
    ''but please leave this note attached'''
    '' - Phill64 (Stack Overflow)      ''''
    ''''''
    ''True Random
    ''''''
    ''This random class uses 4 factors most likely to change:
    ''System Timer
    ''System Memory (RAM)
    ''CPU Usage
    ''Mouse Position
    ''''''
    ''Why is this class true random and the pre-packaged one isn't you ask?
    ''Because classic uses just the timer as a seed, and a pattern to generate from then on
    ''Whereas, this class only follows patterns for a limited time(long enough for new data to come in)
    ''and the fact it uses RAM and the Mouse Position means it is effected by unknown sources.
    ''the system clock spins circles, so it will of course create a pattern
    ''a user moving his mouse is COMLETELY unpredictable
    ''RAM is effected continuously in ways that can never be predicted(within reason)
    ''CPU performance is effected by everything running and even the weather! thus the CPU can also never be accurately predicted
    ''''''
    ''How did I test the results?
    ''''''
    ''by creating 2 classes of the classic Random
    ''and 2 classes of TrueRandom
    ''then making all 4 create a list of random numbers
    ''classic random generated 2 IDENTICAL lists every time i tested
    ''whereas the 2 TrueRandom classes would create 2 different lists
    '''''
    ''Conclusion:
    ''this class, created under all the same conditions returns different results
    ''that.. is truely random.

    'these variables make a temporary pattern,
    'long enough for data to change
    Private betTick As Double 'between ticks
    Private lastRAM As Decimal 'last value from memory
    Private tempPat As Integer 'small pattern iterater
    Public Function GetNext(ByRef lower As Integer, ByRef upper As Integer) As Integer
      'get system timer
      betTick = (betTick + Now.Ticks) / 2  'between ticks, gradually move towards next tick of the system clock

      'get system RAM
      Dim RAM As Decimal 'where we'll put information taken from RAM
      Dim i As Integer
      For i = 0 To 40
      RAM = ((RAM + Threading.Thread.VolatileRead(betTick + i)) / 2) 'retrieve next byte and average with last
      Next
      RAM = Mid(((lastRAM + RAM) / 2).ToString, 5) 'average RAM just retrieved with last RAM retrieved
      lastRAM = RAM

      'apply timer,RAM,CPU and Mouse
      tempPat += 1
      If tempPat > 20 Then tempPat = 1
      Dim v As Double = (RAM / tempPat) + ((betTick / 100) + CPUUsage() + (Cursor.Position.X / Cursor.Position.Y))
      Dim rand As Decimal = (v / 1000) - Math.Floor(v / 1000)

      'ratio the random decimal number to the required bounds
      Return CLng(lower + (rand * (upper - lower)))
    End Function

    ''CPU Usage code from: http://www.theserverside.net/discussions/thread.tss?thread_id=26337
    Private Function CPUUsage() As Double
      Dim myCounter As System.Diagnostics.PerformanceCounter = New System.Diagnostics.PerformanceCounter
      myCounter.CategoryName = "Processor"
      myCounter.CounterName = "% Processor Time"
      myCounter.InstanceName = "_Total"
      Return myCounter.RawValue
    End Function

End Class
I ask everyone if he didn't steal anything else... 😠
(Sep 1, 2014 01:08 AM)CottleSilver Wrote:  You didn't do this: http://www.vbforums.com/showthread.php?3...-Generator.
The code from the link above (Attached Files):
Code
Public Class TrueRandom
    ''''''
    ''Use this class at will      ''''
    ''but please leave this note attached'''
    '' - Phill64 (Stack Overflow)      ''''
    ''''''
    ''True Random
    ''''''
    ''This random class uses 4 factors most likely to change:
    ''System Timer
    ''System Memory (RAM)
    ''CPU Usage
    ''Mouse Position
    ''''''
    ''Why is this class true random and the pre-packaged one isn't you ask?
    ''Because classic uses just the timer as a seed, and a pattern to generate from then on
    ''Whereas, this class only follows patterns for a limited time(long enough for new data to come in)
    ''and the fact it uses RAM and the Mouse Position means it is effected by unknown sources.
    ''the system clock spins circles, so it will of course create a pattern
    ''a user moving his mouse is COMLETELY unpredictable
    ''RAM is effected continuously in ways that can never be predicted(within reason)
    ''CPU performance is effected by everything running and even the weather! thus the CPU can also never be accurately predicted
    ''''''
    ''How did I test the results?
    ''''''
    ''by creating 2 classes of the classic Random
    ''and 2 classes of TrueRandom
    ''then making all 4 create a list of random numbers
    ''classic random generated 2 IDENTICAL lists every time i tested
    ''whereas the 2 TrueRandom classes would create 2 different lists
    '''''
    ''Conclusion:
    ''this class, created under all the same conditions returns different results
    ''that.. is truely random.

    'these variables make a temporary pattern,
    'long enough for data to change
    Private betTick As Double 'between ticks
    Private lastRAM As Decimal 'last value from memory
    Private tempPat As Integer 'small pattern iterater
    Public Function GetNext(ByRef lower As Integer, ByRef upper As Integer) As Integer
      'get system timer
      betTick = (betTick + Now.Ticks) / 2  'between ticks, gradually move towards next tick of the system clock

      'get system RAM
      Dim RAM As Decimal 'where we'll put information taken from RAM
      Dim i As Integer
      For i = 0 To 40
      RAM = ((RAM + Threading.Thread.VolatileRead(betTick + i)) / 2) 'retrieve next byte and average with last
      Next
      RAM = Mid(((lastRAM + RAM) / 2).ToString, 5) 'average RAM just retrieved with last RAM retrieved
      lastRAM = RAM

      'apply timer,RAM,CPU and Mouse
      tempPat += 1
      If tempPat > 20 Then tempPat = 1
      Dim v As Double = (RAM / tempPat) + ((betTick / 100) + CPUUsage() + (Cursor.Position.X / Cursor.Position.Y))
      Dim rand As Decimal = (v / 1000) - Math.Floor(v / 1000)

      'ratio the random decimal number to the required bounds
      Return CLng(lower + (rand * (upper - lower)))
    End Function

    ''CPU Usage code from: http://www.theserverside.net/discussions/thread.tss?thread_id=26337
    Private Function CPUUsage() As Double
      Dim myCounter As System.Diagnostics.PerformanceCounter = New System.Diagnostics.PerformanceCounter
      myCounter.CategoryName = "Processor"
      myCounter.CounterName = "% Processor Time"
      myCounter.InstanceName = "_Total"
      Return myCounter.RawValue
    End Function

End Class
I ask everyone if he didn't steal anything else... 😠

I apologize, I shouldve checked if he took it from an online source. Anyway, enjoy.
Lol, when you're caught stealing, you edit the post saying it was you and your friend, how clever.
(Sep 1, 2014 03:35 AM)He B TeMy Wrote:  Lol, when you're caught stealing, you edit the post saying it was you and your friend, how clever.

Yea coz somebody waits 7 years before posting a code... The op stole a code and posted as it's own, the end.😑
Random is random enough already, trust me. I've spent hours examining the randomness of that and there is absolutely no need for an inprovement, after all, nothing is absolutely random. No need for this.
This is far from "100% random". The built-in Random class works perfectly fine if you use it correctly, which you obviously don't. Additionally your method is really slow compared to the .NET implementation.
Probably coding some useless shit.
That's not 100% random. This is pseudo random, the only random way a computer can do. And the Random class is based on the time the computer was on (Environment.TickCount).

Code
Public Sub New()
    Me.New(Environment.TickCount)
End Sub

You can try to remove that similar with different seed. Just use any hardware property as value and that's all. No need to create a new function when it's already done.

http://en.wikipedia.org/wiki/Pseudorandomness
http://stackoverflow.com/questions/12076...om-numbers
Did some testing just for fun, and to give you a representation of why trying to implement stuff like this yourself is not a good idea I'll show you a quick benchmark test result:

Generating 100000 random numbers from 0 to int32.maxvalue with your function:
15500ms

Generating 100000 random numbers from 0 to int32.maxvalue with Random.Next():
2ms
Probably coding some useless shit.
(Sep 1, 2014 07:36 AM)ubbelol Wrote:  Did some testing just for fun, and to give you a representation of why trying to implement stuff like this yourself is not a good idea I'll show you a quick benchmark test result:

Generating 100000 random numbers from 0 to int32.maxvalue with your function:
15500ms

Generating 100000 random numbers from 0 to int32.maxvalue with Random.Next():
2ms
i had problems with it as well, solved it by initializing the random instance with RNGCryptoServiceProvider
(Sep 1, 2014 03:35 AM)He B TeMy Wrote:  Lol, when you're caught stealing, you edit the post saying it was you and your friend, how clever.

Actually when I edited the thread, I labeled it with an EDIT:: tab. It was there from the start
(Sep 1, 2014 12:04 PM)PapaBeans Wrote:  Actually when I edited the thread, I labeled it with an EDIT:: tab. It was there from the start

I remember the original thread, you edited the part about 'the friend', stop the bullshit
(Sep 1, 2014 12:04 PM)PapaBeans Wrote:  Actually when I edited the thread, I labeled it with an EDIT:: tab. It was there from the start
You shouldn't lie: http://webcache.googleusercontent.com/se...clnk&gl=en
(Sep 1, 2014 12:55 PM)Mr.Steven Wrote:  You shouldn't lie: http://webcache.googleusercontent.com/se...clnk&gl=en

Ouch. Let's see what OP has to say to this 😝
Like UbbeLol and others said... this is not completely random, it is in some way of course since it's showing you a different number each time you'd maybe call it
But this thing is using too many API's, and if you'd have had some super computer and calling the function twice it could show the same result
The Cursor.Position may even throw a error when using it in a Windows Service, not sure about it

Maybe a fun way of making a random function is to generate a big array from 0 to 100000 and using the Fisher–Yates shuffle algorithm, still not random enough, but fun todo