Iv e 一直在研究一个 Perlin 脚本, 但是在创建简单的伪随机值时遇到了问题 。
我需要能够从 xy 坐标创建种子值, 但 x+y 与重复值有明显问题 。 而且它们会进入负空格, 所以 x- y 无效 。
对不起,如果这个问题已经被解答到别处,但要么我不明白,要么找不到。
Iv e 一直在研究一个 Perlin 脚本, 但是在创建简单的伪随机值时遇到了问题 。
我需要能够从 xy 坐标创建种子值, 但 x+y 与重复值有明显问题 。 而且它们会进入负空格, 所以 x- y 无效 。
对不起,如果这个问题已经被解答到别处,但要么我不明白,要么找不到。
你需要更好地定义问题 才能得到最佳的答案
如果您的 x 和 y 值相对较小, 您可以将其放置在整数的高低部分( 您语言中的种子是整数), 例如, 32 位平台 :
int 种子 = x & lt; & lt; 16 + y;
如果种子值不允许为负值(我并不完全理解你的问题中“负空间”指的是什么,你指的是地理还是种子值),你可以选择种子的绝对值。
如果你的意思是坐标可能有负值, 你的最佳行动方针取决于你是否想要同一个种子来做一个坐标, 而对于它来说是相反的。
您想要为每个 x, 配对的 x 提供一个可重复的随机数吗?
Using a linear or in general function combination of the x,y as a seed will give artifacts in the distribution (at least if you don t use a very complex function). Try with this, I ve the same problem ant it worked for me
//seeded random for JS - integer
function irnd2()
{
a=1664525;
c=1013904223;
m=4294967296;
rnd2.r=(rnd2.r*a+c)%m;
return rnd2.r;
}
//seeded random for JS - double [0,1]
function rnd2()
{
a=1664525;
c=1013904223;
m=4294967296;
rnd2.r=(rnd2.r*a+c)%m;
return rnd2.r/m;
}
rnd2.r=192837463;
//seed function
function seed2(s)
{
s=s>0?s:-s;
rnd2.r=192837463^s;
}
//my smart seed from 2 integer
function myseed(x,y)
{
seed2(x);//x is integer
var sx=irnd2();//sx is integer
seed2(y);//y is integer
var sy=irnd2();//sy is integer
seed2(sx^sy);//using binary xor you won t lose information
}
为了使用:
myseed(x,y);
irnd2();
这样,你就可以获得一个良好的非与气候有关的随机序列。
我用在联署材料中, 但它也应该用其他语言工作, 假设种子的论据, 圆圆的回报值是整数。
先使用 >x
和 y
的绝对值; 然后, x_y
将运作良好。 创建伪随机源的最容易的方法之一是时间。 您可以尝试在当前系统时间乘以 x_y
; 这个方法生成重复种子值的可能性极小 。
如果您知道数值的范围, 您可以简单地将 x 和 y 投入为带零的字符串, 附加两个字符串, 然后通过散列函数运行由此产生的字符串 。
在 C # 中, 从 lexroat 答案中修改和改进。 请设置 < code> random. seed = MyUtils. Get SedXY( x, y) < /code >, 并且您准备就绪 。
public static class MyUtils
{
static int seed2(int _s)
{
var s = 192837463 ^ System.Math.Abs(_s);
var a = 1664525;
var c = 1013904223;
var m = 4294967296;
return (int) ((s * a + c) % m);
}
public static int GetSeedXY(int x, int y)
{
int sx = seed2(x * 1947);
int sy = seed2(y * 2904);
return seed2(sx ^ sy);
}
}
I m trying to implement a weighted random numbers. I m currently just banging my head against the wall and cannot figure this out. In my project (Hold em hand-ranges, subjective all-in equity ...
There are a lot of questions about salts and best practices, however most of them simply answer very specific questions about them. I have several questions which feed into one another. Assuming a ...
I am working on a php site in which we have to upload images from users.i have to rename that file for preventing conflicts in the name of the image. uniqid(rand(), true); and adding a large random ...
How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.
According to various sources, such as Wikipedia and various .edu websites found by Google, the most common ways for a hash table to resolve collisions are linear or quadratic probing and chaining. ...
I m pulling my hair out trying to build a little random photo JSON feed using DataMapper/Sinatra. Here s what I have so far.. Photo.favorites.to_json(:methods => [:foo, :bar]) So that works fine. ...
Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...
I have two animation sequences, and I want one of them to play randomly when a button is pressed. Here is the code: { color.animationImages = [NSArray arrayWithObjects: [...