- Home /
The question is answered, right answer was accepted
Seeding perlin functions
Simple question. Is there a way to seed the Mathf.PerlinNoise function?
Typically you randomize the $$anonymous$$athf.PerlinNoise() by randomizing the offset where you start.
But the question is if I can use a string like "banans" or "404" to create the randomization
If you want to use a string, then you need to use some sort of function that maps a string into two semi-random floating point numbers. Then you can use the code @DaveA provided:
 using UnityEngine;
 using System.Collections;
 
 public class Bug20 : $$anonymous$$onoBehaviour {
     
 string input = "";
 Rect rect = new Rect(100,100,200,50);
         
     float Hash(string st, int prime) {
             int val = 0;
             for (int i = 0; i < st.Length; i++)
                 val = (val + st[i]) % prime;
             
             return (float)val/prime;
     }
     
     void Update() {
         Debug.Log (Hash (input, 263) + ", " + Hash(input, 193));
     }
         
     void OnGUI() {
         input = GUI.TextField(rect, input);    
 
     }
 }
The distribution of numbers returned by Hash() won't be great, but for what I think you are trying to do, it should work fine.
Answer by DaveA · Aug 18, 2013 at 06:28 PM
I don't think so but it's easy. Manual says: "The same coordinates will always return the same sample value but the plane is essentially infinite so it is easy to avoid repetition by choosing a random area to sample from." as robertu says too.
The code in the manual, you would set xOrg and yOrg to your 'seed'. Here's a way to randomize that.
 var xOrg: float = Random.value;
 var yOrg: float =  Random.value;
 var xCoord = xOrg + x / noiseTex.width * scale;
 var yCoord = yOrg + y / noiseTex.height * scale;
 var sample = Mathf.PerlinNoise(xCoord, yCoord);
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                