asp.net中的randomval()方法 [英] randomval() method in asp.net

查看:82
本文介绍了asp.net中的randomval()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用randomval()函数获取随机值...

这是我的编码...

 val = randomval (1,4); //这里val是int数据类型变量





i想知道它会不会返回4(代码已经给了我1,2和3)。

谢谢。

解决方案

我猜randomval是一个自定义实现。 />
所以它实际上取决于randomval的实现方式。



如果你需要关于随机 class,你可以找到它这里 [ ^ ]。


为了生成随机值,您可以使用通用唯一编号。这是 GUID。它永远不会再次生成相同的数字。



 //这个代码示例演示了Guid.NewGuid()方法。 

使用System;

class样本
{
public static void Main()
{
Guid g;
//创建并显示两个GUID的值。
g = Guid.NewGuid();
Console.WriteLine(g);
Console.WriteLine(Guid.NewGuid());
}
}

/ *
此代码示例产生以下结果:

0f8fad5b-d9cb-469f-a165-70867728950e
7c9e6679-7425-40de-944b-e07fc1f90ae7

* /





欲了解更多信息:< a href =http://msdn.microsoft.com/en-us/library/system.guid.newguid(v=vs.110).aspx> GUID


< blockquote>在哪里定义了randomval()方法。你能发贴吗?



如上所述,答案取决于这种方法的实施。



我所知道的是,在.NET中, Random 类有一个 Next()方法,它接受两个参数,用于指定要获取的样本的边界。下限是包含的,而上限是独占的。因此,在此实现中, Next(1,4)永远不会返回4.


i am using randomval() function to get a random value...
here is my coding...

val = randomval(1, 4);//here val is int datatype variable



i want to know will it ever return 4(the code is already giving me 1,2 and 3).
Thanks.

解决方案

I guess randomval is a custom implementation.
So it really depends on how randomval has been implemented.

If you need more information on the Random class, you can find it here[^].


For generate the random values you can use the universal unique number.that is GUID.It never generates the same number again ever.

// This code example demonstrates the Guid.NewGuid() method. 

using System;

class Sample 
{
    public static void Main() 
    {
    Guid g;
// Create and display the value of two GUIDs.
    g = Guid.NewGuid();
    Console.WriteLine(g);
    Console.WriteLine(Guid.NewGuid());
    }
}

/*
This code example produces the following results:

0f8fad5b-d9cb-469f-a165-70867728950e
7c9e6679-7425-40de-944b-e07fc1f90ae7

*/



For more info : GUID


Where is randomval() method defined. Could you post it?

As this has been stated, the answer depends on the implementation of this method.

What I know is that, in .NET, the Random class has a Next() method which accepts two argument to specify the bounds of the sample that is to be obtained. The lower bound is inclusive, whereas the upper one is exclusive. So, in this implementation, Next(1, 4) can never return 4.


这篇关于asp.net中的randomval()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆