Source language: Translate to:

Randomize Code

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Postby Sam Cox » Tue Mar 13, 2007 3:42 am

Neobook's Random "N" function returns a value between 0 and N-1. The FileRead parameter expects a number between 1 and the number of lines in the file. Executing FileRead "filename" "0" "[variable]" probably explains the odd characters you're getting.

See if this shorter and more adaptable code works for you:
Code: Select all
SetVar "[DesiredLength]" "6"
SetVar "[Zero]" ""
FileLen "[PubDir]words.txt" "[NumOfLines]"
Loop "1" "[DesiredLength]" "[unused]"
  Random "[NumOfLines]-1" "[R]"
  FileRead "[File]" "[R]+1" "[Char]"
  SetVar "[Zero]" "[Zero][Char]"
EndLoop

In this application, you don't really to read from an external file. You could randomly select characters from a string.
Code: Select all
SetVar "[Base]" "abcd...ABCD...0123..."
StrLen "[Base]" "[BaseLength]"
SetVar "[DesiredLength]" "6"
SetVar "[Zero]" ""
Loop "1" "[DesiredLength]" "[unused]"
  Random "[BaseLength]-1" "[R]"
  SubStr "[Base]" "[R]+1" "1" "[Char]"
  SetVar "[Zero]" "[Zero][Char]"
EndLoop
User avatar
Sam Cox
 
Posts: 768
Joined: Fri Apr 01, 2005 7:30 am
Location: Loveland CO USA


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest