From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 2FB1347B81 for ; Tue, 2 Jan 2024 11:06:40 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C5E6668CA9D; Tue, 2 Jan 2024 13:06:37 +0200 (EET) Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4DC5868AABD for ; Tue, 2 Jan 2024 13:06:32 +0200 (EET) Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a2830574764so78514966b.1 for ; Tue, 02 Jan 2024 03:06:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704193591; x=1704798391; darn=ffmpeg.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=Gwf9N46C/JA30j9ykiw8AQncG4DUZ+OjDkFUIGfs4fM=; b=kbdFQ3DXYgfu/Nm2inCafizgIZbgliP3mhrDCmP4xs/bC7KDtPjeIF51gpSKrJGEwY L2YqD7vp02GbU+3xTjUW5+kxF0A/7JD+bE54AO+sD1/o5tv348v0U5lfvwCI6rAMtKb+ KxcLQaAyN6TtCVVWBg1/rL+3zsv5qVtf6rEQix3I7d8HtnSXxO9D0P9oMR1PT1MxjCop I4ZBethGCkM/vayTAwFWtzKeaDYIuAlN7nEKG3s3ugW3QU1YdjtkXgRUFncVWEbq3new Y/Bynq5hzYjqvyNFVNH4bt5crjE9O3VDzGKZXnIr95vmTg5QdtIPHmMtNIpVyaDP1KYD vuoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704193591; x=1704798391; h=user-agent:in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Gwf9N46C/JA30j9ykiw8AQncG4DUZ+OjDkFUIGfs4fM=; b=PfcdkNpNUBC/m/VBxqtLaFy/lwjZA3RcSr0azu/rF9v7fmwhfXCp+fzbhtD+a0eoR0 KqOcmVDxxsVYoLNjkVfmZ/+Alrq8aQwzTPz70eo8LUc6VwcAVbruCoRnz46qiNGA1rKs ShhN+fCTTic1e+3rhgsgO5Ou+jCy3ZhKsoLhMgKR5+GTonHu+gR2Ap8C0LEu7QLj2KxG D74QkWlnUqXV3T/h/gehnvl7e0uCyNvPteeLY96hkx7555SEJhuz88O69nLlO3Xpd0jI NJNtbN4u9Q+JIioMes/TF119skoVTv+zC/Lx0ntB3yQglrOZFSxy4vxdpipF3+QlHIJ4 lUCw== X-Gm-Message-State: AOJu0YzY2Rix1DWgAEW1ObdPVVC3Lvh/7htKrC9zg5UwJLZiGef+0f6t 8U+qAOE0b35zIAMJtO5x9IJvpiMFjyY= X-Google-Smtp-Source: AGHT+IGA/2HOOjYu0iNDfzfgvH9vTyZAAU6AYzaY7tBoOEvhjeismA3eKj5A49W87V7+hHtkRkUq/g== X-Received: by 2002:a17:906:a186:b0:a26:9113:4c52 with SMTP id s6-20020a170906a18600b00a2691134c52mr8190607ejy.32.1704193590643; Tue, 02 Jan 2024 03:06:30 -0800 (PST) Received: from mariano (dynamic-adsl-84-220-189-10.clienti.tiscali.it. [84.220.189.10]) by smtp.gmail.com with ESMTPSA id le19-20020a170906ae1300b00a2798d33c31sm3800643ejb.77.2024.01.02.03.06.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 03:06:30 -0800 (PST) Received: by mariano (Postfix, from userid 1000) id 1DA3FBFCDC; Tue, 2 Jan 2024 12:06:29 +0100 (CET) Date: Tue, 2 Jan 2024 12:06:29 +0100 From: Stefano Sabatini To: FFmpeg development discussions and patches Message-ID: Mail-Followup-To: FFmpeg development discussions and patches References: <20240102022845.9916-1-michael@niedermayer.cc> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240102022845.9916-1-michael@niedermayer.cc> User-Agent: Mutt/2.1.4 (2021-12-11) Subject: Re: [FFmpeg-devel] [PATCH] avutil/eval: Use integer for random() state X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On date Tuesday 2024-01-02 03:28:45 +0100, Michael Niedermayer wrote: > rounding the 64bit integer state to double between each iteration > causes a reduction in quality of the random number generator. > For example its period drops from 2^64 to around 200 million > > Signed-off-by: Michael Niedermayer > --- > libavutil/eval.c | 16 +++++++++++++--- > 1 file changed, 13 insertions(+), 3 deletions(-) > > diff --git a/libavutil/eval.c b/libavutil/eval.c > index bad9e4ecb8d..89c61ba4bf5 100644 > --- a/libavutil/eval.c > +++ b/libavutil/eval.c > @@ -55,6 +55,7 @@ typedef struct Parser { > void *log_ctx; > #define VARS 10 > double *var; > + uint64_t *var_uint64; > } Parser; > > static const AVClass eval_class = { > @@ -173,6 +174,7 @@ struct AVExpr { > } a; > struct AVExpr *param[3]; > double *var; > + uint64_t *var_uint64; > }; > > static double etime(double v) > @@ -230,9 +232,10 @@ static double eval_expr(Parser *p, AVExpr *e) > } > case e_random:{ > int idx= av_clip(eval_expr(p, e->param[0]), 0, VARS-1); > - uint64_t r= isnan(p->var[idx]) ? 0 : p->var[idx]; > + uint64_t r= p->var_uint64[idx] ? p->var_uint64[idx] : (isnan(p->var[idx]) ? 0 : p->var[idx]); > r= r*1664525+1013904223; > p->var[idx]= r; > + p->var_uint64[idx]= r; > return e->value * (r * (1.0/UINT64_MAX)); > } > case e_while: { > @@ -319,7 +322,11 @@ static double eval_expr(Parser *p, AVExpr *e) > case e_div: return e->value * (d2 ? (d / d2) : d * INFINITY); > case e_add: return e->value * (d + d2); > case e_last:return e->value * d2; > - case e_st : return e->value * (p->var[av_clip(d, 0, VARS-1)]= d2); > + case e_st : { > + int index = av_clip(d, 0, VARS-1); > + p->var_uint64[index] = 0; can't you set this to d2 and then in case e_random: uint64_t r = isnan(p->var[idx]) ? 0 : p->var_uint64[idx]; ? _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".