Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Random Next and Seed
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Prince Pwn




PostPosted: Sat Jan 16, 2010 1:34 pm   Post subject: Random Next and Seed

What is it you are trying to achieve?
I wish to make a seed for my random generation for an encryption algorithm. I Need the same sequence of letters to stay every time I execute the program.


What is the problem you are having?
Not too sure how the different Rand methods work together.


Describe what you have tried to solve this problem
Scoured the Turing Help file through Rand.Set, nat, and Rand.Seed. Found it pretty confusing.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Turing:


/*
 Author: 
 Program: Encryption v1.0
 Date:      1/16/2010
 */


const ubound := 26                          % Size of alphabet
var randNum : int                           % Used to hold a random number
var letter : array 1 .. ubound of char      % Stores each letter in order
var storage : array 1 .. ubound of char     % Stores each letter perminantely

for i : 1 .. ubound                         % Counts the alphabet
    letter (i) := chr (64 + i)              % Fills each letter uniquely and in order
end for

for decreasing i : ubound .. 1              % Counting alphabet backwards
    randNum := Rand.Int (1, i)              % Sets random letter from 'a' to 'z,y,x...'
    storage (i) := letter (randNum)         % Store random letter into storage
    letter (randNum) := letter (i)          % Sets that random letter back where it cannot be reached on next loop
end for

for i : 1 .. ubound                         % Output characters to the screen
    put storage (i) ..
end for



Please specify what version of Turing you are using
Version 4.1
Sponsor
Sponsor
Sponsor
sponsor
TerranceN




PostPosted: Sat Jan 16, 2010 2:04 pm   Post subject: RE:Random Next and Seed

Use Rand.Set. This sets what the pseudo-random generator is using to determine values. Since the generator is pseudo-random having the same seed every time will yeild the same results. For example after adding Rand.Set(1) to your program:

Turing:
/*
 Author:
 Program: Encryption v1.0
 Date:      1/16/2010
 */


const ubound := 26                          % Size of alphabet
var randNum : int                           % Used to hold a random number
var letter : array 1 .. ubound of char      % Stores each letter in order
var storage : array 1 .. ubound of char     % Stores each letter perminantely

Rand.Set(1)

for i : 1 .. ubound                         % Counts the alphabet
    letter (i) := chr (64 + i)              % Fills each letter uniquely and in order
end for

for decreasing i : ubound .. 1              % Counting alphabet backwards
    randNum := Rand.Int (1, i)              % Sets random letter from 'a' to 'z,y,x...'
    storage (i) := letter (randNum)         % Store random letter into storage
    letter (randNum) := letter (i)          % Sets that random letter back where it cannot be reached on next loop
end for

for i : 1 .. ubound                         % Output characters to the screen
    put storage (i) ..
end for


It now always outputs

code:
MZRPOKIAGYXWNBEDVFLJHCTUQS
Prince Pwn




PostPosted: Sat Jan 16, 2010 2:09 pm   Post subject: RE:Random Next and Seed

Ah, I see. And changing the 'key' or 'seed' will output different values but if I use the same key it stays the same. Thanks Very Happy

But if I were to say re-code in C++ or Java, could I use the same seed as in Turing and get the same results?
TerranceN




PostPosted: Sat Jan 16, 2010 2:23 pm   Post subject: RE:Random Next and Seed

It depends on how they generate pseudo-random numbers. If it is the same as Turing, then yes. But I have no idea how Turing generates it (and since it's closed source, only holtsoft knows), so you would have to test it in order to figure it out.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: