Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

The same random numbers

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-13-2008, 11:28 PM
LineCutter's Avatar
Senior Member
 
Join Date: May 2007
Location: Daarsit
Posts: 161
Awards Showcase
Beta Tester 
Total Awards: 1
Question The same random numbers

I might have missed this, but is there a way to specify a seed value to the rnd() function so that the same pseudo-random sequence is generated each time?
Reply With Quote
  #2 (permalink)  
Old 10-14-2008, 05:50 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,733
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

You can do it with the Door library:
Code:
Sub Globals
    
'Declare the global variables here.

End Sub

Sub App_Start
    Random.New1(
False)
    Seed.New1(
1)
    Seed.SetValue(
0,75,"System.Int32"'Set the seed value
    Random.CreateNew2("System.Random",Seed.Value)
    
    
Msgbox(MyRnd(0,10))
    
Msgbox(MyRnd(0,10))
End Sub

Sub MyRnd(Minimum, Maximum)
    
Return Random.RunMethod3("Next",Minimum,"System.Int32",Maximum,"System.Int32")
End Sub
Attached Files
File Type: sbp Random.sbp (542 Bytes, 15 views)
Reply With Quote
  #3 (permalink)  
Old 10-15-2008, 10:05 PM
LineCutter's Avatar
Senior Member
 
Join Date: May 2007
Location: Daarsit
Posts: 161
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Thanks. That helps me create a password for the crypto question that agraham helped me with. Since it won't be physically present in the code it'll be that little bit harder for the casual hacker to bypass.
Code:
AF0="A1B2C3D4E5F67890"
    n=
""
    
For i = 0 To 64
 n=n&StrAt(AF0,Random.RunMethod3(
"Next",0,"System.Int32",StrLength(AF0),"System.Int32"))
    
Next
Reply With Quote
  #4 (permalink)  
Old 10-16-2008, 08:31 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by LineCutter View Post
That helps me create a password for the crypto question that agraham helped me with.
That's a good idea! Why not take it a bit further and generate the characters directly? In this case printable ASCII ones. As an aside why 65 characters in n?

Code:
n=""
For i = 0 To 64
   n=n&
Chr(Random.RunMethod3("Next"33"System.Int32"127"System.Int32")))
Next
Reply With Quote
  #5 (permalink)  
Old 10-16-2008, 05:05 PM
LineCutter's Avatar
Senior Member
 
Join Date: May 2007
Location: Daarsit
Posts: 161
Awards Showcase
Beta Tester 
Total Awards: 1
Default

The code was from an "obfuscate as hex values" routine from a test program, hence the limited characters used.

As for 65 values... well I'm clearly not a coder yet!
(Although it was an arbitrary number the intention was for 64 characters, regardless of the fact that they would then go through the MD5 -> DES.key processing you help me with a few days back)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Numbers lock key davelew1s Questions (Windows Mobile) 0 06-14-2008 07:26 PM
B4PObject numbers Louis Questions (Windows Mobile) 1 05-14-2008 08:51 PM
List of possible combinations for x numbers. EdQas Questions (Windows Mobile) 3 10-07-2007 09:18 AM
Line numbers adder derez Share Your Creations 0 07-15-2007 12:27 PM
how to random shuffle an array? Stellaferox Questions (Windows Mobile) 9 07-01-2007 10:48 AM


All times are GMT. The time now is 07:46 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0