This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-12-17 23:00:11

SeanCanoodle
Scratcher
Registered: 2008-06-20
Posts: 100+

Random Seed

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

 

#2 2010-12-17 23:32:10

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: Random Seed

Hi SeanCanoodle  big_smile   big_smile   big_smile  Your City Creator and 3D Cube and Train Creator is awesome  big_smile   big_smile   big_smile

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...  hmm

Last edited by Jonathanpb (2010-12-17 23:32:22)


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#3 2010-12-17 23:51:01

SeanCanoodle
Scratcher
Registered: 2008-06-20
Posts: 100+

Re: Random Seed

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

 

#4 2010-12-18 00:25:33

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: Random Seed

Wow, that's a cool idea! But I don't know how to do that either  sad  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)


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#5 2010-12-18 05:08:24

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Random Seed

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!


You can now reach me on Twitter @johnnydean1_

Offline

 

#6 2010-12-18 16:43:22

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: Random Seed

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


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#7 2010-12-19 12:13:29

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: Random Seed

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)


/* No comment */

Offline

 

#8 2010-12-19 16:36:02

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Random Seed


You can now reach me on Twitter @johnnydean1_

Offline

 

Board footer