-3

Have been trying to create a small program to encrypt/decrypt an text file.

Would like to use RND() function that has been seeded with 4 numbers (0-255). Did it in BASIC years ago on my Apple IIE and it worked great!(255^4=4,294,967,296 possible combos). 'Poked' 4 key numbers into memory locations, ran a small loop to print out 25 random numbers. 'Poked' the same numbers into memory locations, ran the program again and the resulting sequence was the same as the first time!

Are there memory to 'peek' & 'poke' like years ago ?

  • If you using vb.net you don't need that old implementations anymore. there is a lot of libraries in dotnet that helps for encryption – AliReza Sabouri Jul 02 '21 at 20:40
  • Thank you both. I have read the documentation and can't find the locations. – James Andrews Jul 03 '21 at 13:59
  • Seeding the random number generator is done using Randomize(Double). Using the same seed will give you the same sequence of pseudo-random numbers. – peterG Jul 03 '21 at 16:14
  • In vb.net you would probably want to use the .net Random class. .net manages the memory usually. You can put your Integers created by the Next method in a List(Of Integer. – Mary Jul 06 '21 at 04:07
  • While there are some abilities to get directly at process memory, these are generally only the province of debuggers these days. There's pretty much always a more explicit way to do things that were done by directly `Poke`ing values into memory back in the day. Among other things, operating systems are much more judicious about what they allow programs to do, both for security and for stability reasons. – Craig Jul 06 '21 at 14:41

1 Answers1

0

In this case you will get the same numbers each time you run the code because you provided the seed, 17. If you call the constructor without a seed you will get different numbers. I believe it is seeded with the system clock.

See MS Docs for Random

Private rnd As New Random(17)

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click 
    Dim lst As New List(Of Integer)
    For i = 0 To 24
        lst.Add(rnd.Next)
    Next
    For Each item In lst
        Debug.Print(item.ToString)
    Next
End Sub

To limit you numbers to specific range pass a parameter to the Next method.

From the docs.

Next(Int32) Returns a non-negative random integer that is less than the specified maximum.

Next(Int32, Int32)
Returns a random integer that is within a specified range.

Mary
  • 14,926
  • 3
  • 18
  • 27