I'm really interested in creating projects using a seeded random number with a string as the seed. Is there any way I could take a string (from the ask/answer blocks) and use this to seed the random number generator?
I thought of making a table of every character with a value so I could get a lexicographical value of a word then use this number with some algorithm to create random values, but it seems like a lot of work. I'd really like to see some way to do this.
Offline
Hi SeanCanoodle
Your City Creator and 3D Cube and Train Creator is awesome
I'm not sure what you mean... are you talking about getting a number based on a string? You could try something like ((length of (String)) * (2)) or something like that...
Last edited by Jonathanpb (2010-12-17 23:32:22)
Offline
I'm actually trying to get a unique set of numbers for every different string you can put. I want a user to enter their name ( well anything really, maybe their favourite food? ) so that I can generate a game level unique to them that only that user ( or others who entered the same code ) could see the same content. Getting the length of string would treat "James" and "Sally" the same, even though they are clearly different. I'd like to use this as another way for users to share with each other cool things they find by experimenting with random level generators and different seed words.
Offline
Wow, that's a cool idea! But I don't know how to do that either
Well, besides the method where you put an item in a list for every single combination (which would be really, really stupid)...
I suppose you could have it count the letters (you know, a = 1, b = 2), and length to give something that isn't unique, but not too bad...
Last edited by Jonathanpb (2010-12-18 00:26:52)
Offline
Have 3 Lists:
Alphabet (a-z lowercase)
ALPHABET (A-Z uppercase)
Other
Then have:
string set to | |
I05 set to 0
size set to (string length)
I01 set to 0
repeat size times [
I01 set to (I01 + 1)
I02 set to (letter I01 of string)
if alphabet contains I02
{
I03 set to 0
repeat until < item 103 of alphabet = I02 >
| I03 set to (I03 + 1)
|________________
I04 set to (join a and I03)
}
else
if ALPHABET contains I02
{
I03 set to 0
repeat until < item 103 of ALPHABET = I02 >
| I03 set to (I03 + 1)
|________________
I04 set to (join A and I03)
}
else
if Other contains I02
{
I03 set to 0
repeat until < item 103 of Other = I02 >
| I03 set to (I03 + 1)
|________________
I04 set to (join O and I03)
}
else
Other add I02
I04 set to (join O and (length of Other) )
}
I05 set to (join I05 and I04)
]
I05 would then be a random code!
Offline
Could you put that into a script in Scratch and upload a picture? I'm not very good with understanding that type of code. :3
Offline
Have a list containing all the symbols, called symbols. Then do this:
[blocks]<ask [What is your name?]>
<set{ string }to( (answer) )>
<set{ io4 }to( 0 )>
<set{ io1 }to( 0 )>
<set{ size }to( length of ( <{ string }> )>
<repeat( <{ size }> )>
<change{ io1 }by( 1 )>
<set{ io2 }to( letter ( <{ io1 }> ) of ( <{ string }> ) )>
<if> <symbols contains <{ io2 }> >
<set{ io3 }to( 0 )>
<repeat until> <( <item <{ io3 }> of symbols> <=> <{ io2 }> )>
<change{ io3 }by( 1 )>
<end>
<else>
<add <{ io2 }> to symbols>
<set{ io3 }to( <length of symbols> )>
<end>
<set{ io4 }to( <join( <{ io4 }> )( <{ io3 }> ) > )>
<end>
[/blocks]
This will create an entirely numeric unique code for every input entered.
It requires Scratch 1.4.
EDIT: Hope you can understand this. The forum blocks are USELESS.
Last edited by TheSuccessor (2010-12-19 12:14:34)
Offline
Offline